0

I'm having a small issue with template inheritance.

If I create an interface class with a template:

template<typename Data>   
class InterfaceClass {
   private:
   public:
      virtual Data* foo() = 0; //some function that returns our template type
}

Then I create an implementation of this:

template<typename MoData>
class Implementation : public InterfaceClass<MoData> {
   private:
   public:
      MoData* foo() { MoData* ptr = NULL; return ptr; } //some implementation
}

I seem to have trouble with this working in my compiler. Is this not legal?

3 Answers 3

3
template<typedef Data>

is not correct.

You should use

template<class Data>

or

template<typename Data> 
Sign up to request clarification or add additional context in comments.

4 Comments

yeah, whoops I have it is typename in my code... not typedef.... my bad... long day lol
@LeeJacobs If you add the missing ; it compiles fine with me : ideone.com/8PeBDB.
@LeeJacobs Sorry I was playing with it, try again :)
ok I tested it out on my system I know what I was doing wrong. Thanks man.
1
template <typedef Data>

is wrong, use

template <typename Data>   

Comments

0

Please add semicolon at the end of class declaration.

template<typename Data>   
class InterfaceClass {
   private:
   public:
      virtual Data* foo() = 0; //some function that returns our template type
};

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.