0

Suppose we have the general function pointer:

template <class ArgT, class RetT, class F>
struct A {
    F f;
public:
    A(F f) : f(f) {}

    RetT operator()(ArgT arg) { return f(arg); }
};

Why does this work?

template <class ArgT, class RetT, class F>
class B {
    A<ArgT, RetT, F> test;
};

... and this not ?

class C {
    template <class ArgT, class RetT, class F>
    A<ArgT, RetT, F> test;
};

error C3857: 'C::test': multiple template parameter lists are not allowed

I need to define a class like in last example (class C), how can I do that?

3
  • 1
    because it doesn't make sense. how can you use it and how can compile generate code for it? Commented Jan 2, 2015 at 10:33
  • 1
    sizeof(C) would be infinite ^_^ Commented Jan 2, 2015 at 10:49
  • Thank you all for your answer. Commented Jan 2, 2015 at 12:13

1 Answer 1

1

Because variables can't have template. In fact just classes and functions can have template.

Edit: As Alan Stokes said, in C++14, variables also can have template.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.