Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > Template Instantiation and member templates.

Reply
Thread Tools

Template Instantiation and member templates.

 
 
amparikh@gmail.com
Guest
Posts: n/a
 
      01-27-2006
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.

 
Reply With Quote
 
 
 
 
Victor Bazarov
Guest
Posts: n/a
 
      01-27-2006
http://www.velocityreviews.com/forums/(E-Mail Removed) wrote:
> 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
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Explicit instantiation of non-template member of template class Noah Roberts C++ 6 02-02-2011 09:53 PM
overloading non-template member functions with template member functions Hicham Mouline C++ 0 04-23-2009 11:42 AM
Explicit instantiation of STL vector demands explicit instantiation of all the templates it using internally. krunalbauskar@gmail.com C++ 1 12-25-2006 03:51 PM
?explicit instantiation member function of class template henkoo@gmail.com C++ 5 12-04-2005 04:06 PM
parse error in gcc but success in vc.net, call a non_template class's template member function from a template class's member function! ken C++ 2 06-28-2005 06:57 AM



Advertisments