3 回答
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".
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.
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.