0

How do I use variables of a template class inside other template classes? On compile, I receive the error clsC is not a template - why?

---- MyClasses.h: ----

template <typename T> class clsA {
public:
    void Foo(typename clsC<T> arg) {...}
    ...
};

template <typename T> class clsB {
public:
    std::vector<clsA<T>> a;
    ...
};

template <typename T> class clsC {
public:
    clsC(typename clsB<T> arg) {...}
    ...
};

There's been a lot of similar questions, but none which have solved my problem so far.

2
  • 1
    Forward declarations... Commented May 4, 2013 at 2:45
  • Ahh I didn't know you could forward declare classes (I'm coming from pure C) - Thanks Commented May 4, 2013 at 2:56

1 Answer 1

3

You probably have to add clsC forward declaration.

template<class T> class clsC; 

Put this line right before clsA's definition.

Also, the following line

std::vector<clsA<T>> a;

should rewrite to

std::vector< clsA<T> > a;

because of compiler misunderstands the symbol ">>".

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.