473,396 Members | 1,775 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

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<gckDTC;//error,why?.........................
//...................
//any other solution for this except for typedef

//typedef TC<gckDTC;//ok

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

Oct 23 '07 #1
2 1699
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
Oct 23 '07 #2
On Oct 23, 12:09 pm, kuangye <kuangye19840...@gmail.comwrote:
>
template<const int i1>
class TC
{
public:
void fn()
{
cout<<"i1 "<<i1<<endl;
}
};

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

//typedef TC<gckDTC;//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 !

Oct 23 '07 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

17
by: Paul MG | last post by:
Hi Template partial specialization always seems like a fairly straightforward concept - until I try to do it :). I am trying to implement the input sequence type (from Stroustrup section...
6
by: jesse | last post by:
I am frustrated by class specialization. i don't think it helps me a lot. suppose we have template <class T> class Talkative { T& t; public:
2
by: SainTiss | last post by:
Hi, If you've got a template class with lots of methods, and then you've got a type which works with the template, except for one method... What you need to do there is specialize the...
8
by: Agent Mulder | last post by:
Hi group, I have a problem with partial template specialization. In the code below I have a template struct Music with one method, play(), and three kinds of music, Jazz, Funk and Bach. When I...
4
by: TT \(Tom Tempelaere\) | last post by:
Comeau compiler complains (too few arguments for class template "B") at line *** #include <memory> template<typename T, size_t n> struct A {}; template<typename T, size_t n> struct B;
9
by: stephen.diverdi | last post by:
Can anyone lend a hand on getting this particular template specialization working? I've been trying to compile with g++ 4.1 and VS 2005. ...
2
by: Barry | last post by:
The following code compiles with VC8 but fails to compiles with Comeau online, I locate the standard here: An explicit specialization of any of the following:
8
by: flopbucket | last post by:
Hi, I want to provide a specialization of a class for any type T that is a std::map. template<typename T> class Foo { // ... };
1
by: Ioannis Gyftos | last post by:
Hello, First the code :) /////////////////////////////////////////////////////////////////////////////////// // in another header file namespace LJC{
6
by: abir | last post by:
i have a template as shown template<typename Sclass Indexer{}; i want to have a specialization for std::vector both const & non const version. template<typename T,typename Aclass...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.