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



 DEVELOP > c-Plus-Plus > is there any way to use macro to specialization a template class...

LINK TO THIS PAGE  


rating :  0   |  0


  Page 1 of 1

1

 
Topic: DEVELOP > c-Plus-Plus
User: "kuangye"
Date: 23 Oct 2007 06:09:42 AM
Object: is there any way to use macro to specialization a template class...
#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;
}
.

User: "=?UTF-8?B?RXJpayBXaWtzdHLDtm0=?="

Title: Re: is there any way to use macro to specialization a template class... 23 Oct 2007 06:55:32 AM
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;
#define DTC TC<gck> // Notice that DTC comes before TC<gck>


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


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


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

--
Erik Wikström
.

User: "tragomaskhalos"

Title: Re: is there any way to use macro to specialization a template class... 23 Oct 2007 08:00:40 AM
On Oct 23, 12:09 pm, kuangye <kuangye19840...@gmail.com> wrote:


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 !
.


  Page 1 of 1

1

 


Related Articles
 

NEWER

pg.1232     pg.940     pg.716     pg.544     pg.412     pg.311     pg.234     pg.175     pg.130     pg.96     pg.70     pg.50     pg.35     pg.24     pg.16     pg.10     pg.6     pg.3     pg.1

OLDER