DEVELOP > c-Plus-Plus > is there any way to use macro to specialization a template class...
| 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 !
.
|
|
|
|

|
Related Articles |
|
|