is there any way to use macro to specialization a template class...

K

kuangye

#include <iostream>
using namespace std;

template<const int i1>
class TC
{
public:
void fn()
{
cout<<"i1 "<<i1<<endl;
}
};

const int gck = 0;
#define TC<gck> DTC;//error,why?.........................
//...................
//any other solution for this except for typedef

//typedef TC<gck> DTC;//ok

void try1()
{
DTC obj1;
obj1.fn();
{
const int gck = 1;
DTC obj1;
obj1.fn();
}
}


int main()
{
try1();
return 1;
}
 
G

Guest

On 2007-10-23 13:09, kuangye wrote:

I do not like macros and tend not to use them so I do not know the
specifics of why this works and yours does not. But notice how macros
are defined, the identifier first and then what it should expand to.
#include <iostream>
using namespace std;

const int gck = 0;
 
T

tragomaskhalos

template<const int i1>
class TC
{
public:
void fn()
{
cout<<"i1 "<<i1<<endl;
}
};

const int gck = 0;
#define TC<gck> DTC;//error,why?.........................
//...................
//any other solution for this except for typedef

//typedef TC<gck> DTC;//ok

Your request is bizarre because the typedef mechanism
that you identify is superior in every regard to the
macro you want to replace it with !
 

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,982
Messages
2,570,185
Members
46,736
Latest member
AdolphBig6

Latest Threads

Top