2
4

3 回答 3

10

You have to use

int main()
{
  Fun<> f {"a", "b", "c"};
}

Because Fun is a template.

It's like if you called "function" instead of "function()" by the fact of not having parameters.

You could say that "you are instantiating a template class so it returns a class".

于 2013-08-04T17:39:27.353 回答
3

Even though you've specified defaults for the template parameters, you need to include an empty parameter list to instantiate the template:

Fun<> f{"a", "b", "c"};

Of course, for that to work you'll still need a ctor for Fun that accepts the three strings you're passing.

Finally (also an "of course") the standard container classes (including vector<std::string>) are not intended to be used as base classes, so this really isn't a good idea in general.

于 2013-08-04T17:39:17.650 回答
2

Fun is still a template, so you have to write code this way:

Fun<> f {"a", "b", "c"};

You also have to provide an appropriate constructor.

于 2013-08-04T17:39:26.387 回答