Template Instantiation and member templates.

A

amparikh

I have something like this.

typedef enum TYPES{ X =0, Y,
Z,
MAX};

template <typename T>
class A
{
public:
typedef T obj;

A(){ }
~A() { }
template < int N>
void Open();
template < int N>
void Close();
private:
obj Object;
};

then I have

template<>
A<SomePreDefinedObject>::A()
{
// call member function of SomePreDefinedObject
}

template<>
template<int N>
A<SomePreDefinedObject>::Open()
{
ASSERT(N < MAX);
// call member function of SomePreDefinedObject

}

template<>
template<int N>
A<SomePreDefinedObject>::Close()
{
ASSERT(N < MAX);
// call member function of SomePreDefinedObject
}


template<>
template<>
A<SomePreDefinedObject>::Open<MAX>()
{
// call member function of SomePreDefinedObject
}

template<>
template<>
A<SomePreDefinedObject>::Close<MAX>()
{
// call member function of SomePreDefinedObject
}

now in main I have

main()
{
A<SomePreDefinedObject> O;

O.Lock<MAX>; //everything is fine //line 1

O.Lock<X>; // I get linker error // Line 2

}

Anyone knows why I could be getting linker error for Line 2 whch says
Lock and Unlock not found? I have the memner template defined for all
values except MAX and then for MAX it is specialized.

Thanks.
 
V

Victor Bazarov

I have something like this.

[...]

now in main I have

[...]

Anyone knows why I could be getting linker error for Line 2 whch says
Lock and Unlock not found? I have the memner template defined for all
values except MAX and then for MAX it is specialized.

Please post _real_ code with which you have troubles. Read FAQ section 5.

V
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top