"Barry" <dh*****@gmail.comwrote in message news:fc**********@aioe.org...
Chris Thomasson wrote:
[...]
>#define M_OPplus(classname_macro) \
typedef classname_macro() \
operator+(const classname_macro()& rhs)
template<typename X, typename Y>
class Test1 {
#define M_Test1() Test1<X,Y>
#define M_Test1 ....
definition and invocation should be identical
[...]
I am not exactly sure what you mean here. Are you suggesting that 'M_Test1'
does not really need to be a macro function? Well, in that case the code
would need to be modified to something like:
____________
#define M_OPplus(classname) \
typedef classname \
operator+(const classname &rhs)
template<typename X, typename Y>
class Test1 {
#define M_Test1 Test1<X,Y>
public:
double run();
M_OPplus(M_Test1);
};
____________
At first glance I thought that the 'M_Test1' macro would be expanded and
then passed to 'M_OPplus' which would produce the original error that the OP
was asking about. After I compiled it (gcc) I realized that it was getting
expanded in the context of the 'M_OPplus'.
I guess the only drawback from this would be that you could not pass the
'classname' parameter to another similar macro function. For instance:
this does not compile:
____________
#define M_Typedef(classname) \
typedef classname
#define M_OPplus(classname) \
M_Typedef(classname) \
operator+(const classname &rhs)
template<typename X, typename Y>
class Test1 {
#define M_Test1 Test1<X,Y>
public:
double run();
M_OPplus(M_Test1);
};
____________
while this does:
____________
#define M_Typedef(classname_macro) \
typedef classname_macro()
#define M_OPplus(classname_macro) \
M_Typedef(classname_macro) \
operator+(const classname_macro()& rhs)
template<typename X, typename Y>
class Test1 {
#define M_Test1() Test1<X,Y>
public:
double run();
M_OPplus(M_Test1);
};
____________
So I guess defining 'M_Test1' as a macro function instead of a plain macro
is more "flexible".
Any thoughts?