Phoeniyx
Phoeniyx

Reputation: 572

Can a C++ container contain template objects? Getting error

I am getting the following error: "unspecialized class template can't be used as a template argument for template parameter '_Kty', expected a real type"

The code I am trying to compile is something like this:

template <typename T> class TypeX;

template <typename T>
class TypeY
{

...
    private:
    std::set<TypeX> m_tree;
}

Btw, including "TypeX.h" (which is a template class) instead of the forward declaration doesn't change anything.

What I am gathering from this error is that since TypeX is "unspecialized" - in the sense that "T" is not defined and TypeX is still in template form, it cannot be the basis of a std::set. But I really want TypeX to be a template of T also such that from within TypeY, I can initialize a new TypeX (template of T) and then insert that new object to m_tree.

Can this be done? Thanks guys.

Upvotes: 1

Views: 116

Answers (1)

Caesar
Caesar

Reputation: 9841

TypeX requires a template parameter. You are not giving it one when you creating the std::set

You can change your code to something more like this

std::set< TypeX<T> > m_tree;

Upvotes: 5

Related Questions