Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 351
  • Last Modified:

Template Classes

Is it possible to have a generic object of a template class?

Example:

template <typename t> class CEvent
{ ...
};

class CEventlist
{ CEvent *event;
 ...
}

event in CEventlist shouldn't use a template parameter and CEventlist shouldn't be templated too.
0
mbruenjes
Asked:
mbruenjes
1 Solution
 
AlexFMCommented:
Absolutely impossible. Template is not real class, actual class is created by compiler only when template is instantiated. For example, CEvent is not class, but CEvent<int> is class. CEvent* gives compiler error, and CEvent<int>* is OK.
You need to think in another direction. For example, template class may be derived from some non-template class (interface), and CEventlist contains pointers to base classes.
0
 
mbruenjesAuthor Commented:
I have suspected something like this. Thanks for your great answer.
0

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now