MACRO和具有两个(或更多)参数的模板 [英] MACRO and template with two ( or more ) parameters
问题描述
嗨
如果以这种方式定义了简单的宏:
#define M_OPplus(classname)typedef classname operator +(const
classname& rhs);
和模板类:
模板< typename X,typename Y>
class Test1
{
public:
double run();
M_OPplus(Test1< X,Y)
};
编译器(VS2003)抱怨:警告C4002:宏的实际
参数太多了。我认为它与
中间的逗号有关,预处理器可能会认为我将两个参数
传递给宏。
是否可以修复它并且是否符合C ++标准?
很多Thx
sw*****@googlemail.com 写道:
嗨
如果用这种方式定义了简单的宏:
#define M_OPplus(classname)typedef classname operator +(const < br $>
classname& rhs);
和模板类:
模板< typename X,typename Y>
class Test1
{
public:
double run();
M_OPplus(Test1< X ,Y)
^
逗号将你的论点分成几部分
写
M_OPplus((Test1< X,Y))
};
编译器(VS2003)抱怨:警告C4002:宏的实际
参数太多了。我认为它与
中间的逗号有关,预处理器可能会认为我将两个参数
传递给宏。
是否有可能修复它并符合C ++标准?
很多Thx
- -
谢谢
Barry
< sw ***** @ googlemail.comwrote in message
新闻:11 ********************** @ y42g2000hsy.googlegr oups.com ...
如果有这样定义的简单宏:
#define M_OPplus(classname)typedef classname operator +(const
classname& rhs);
和模板类:
模板< typename X,typename Y>
class Test1
{
public:
double run();
M_OPplus(Test1< X,Y)
};
编译器(VS2003)抱怨:警告C4002:太多实际的
参数对于宏,。我认为它与
中间的逗号有关,预处理器可能会认为我将两个参数
传递给宏。
你的正确。
是否可以修复它并且符合C ++标准?
是的。你可以使用一个小技巧,包括将一个宏的名称
函数传递给M_OPplus宏,该宏调用它来获取令牌。
这样的东西:
#define M_OPplus(classname_macro)\
typedef classname_macro()\
operator +(const classname_macro()& rhs)
模板< typename X,typename Y>
class Test1 {
#define M_Test1()Test1< X,Y>
公开:
双跑();
M_OPplus(M_Test1);
};
看看我是什么到达这里?
" Barry" < dh ***** @ gmail.com在消息新闻中写道:fc ********** @ aioe.org ...
sw ***** @ googlemail.com 写道:
[.. 。]
逗号将你的论点分成几部分
写
M_OPplus( (Test1< X,Y))
[...]
这会引入额外的括号,这可能会破坏语法。例如:
这有一个语法错误:
_______________
#define M_OPplus(classname)\
typedef classname \
operator +(const classname& rhs)
template< typename X,typename Y>
class Test1 {
public:
double run();
M_OPplus((Test1< X,Y>));
};
_______________
这不是:
_______________
#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>
public:
double run();
M_OPplus(M_Test1);
};
_______________
Hi
if have simple macro defined this way:
#define M_OPplus( classname ) typedef classname operator+(const
classname& rhs);
and a template class :
template<typename X, typename Y>
class Test1
{
public:
double run();
M_OPplus( Test1<X,Y)
};
The compiler (VS2003) is complaining : warning C4002: too many actual
parameters for macro, . I think it is related to the comma in the
middle , the preprocessor may think that i am passing two parameters
to the macro.
Is it possible to fix it and does it conform with the C++ standart?
Many Thx
sw*****@googlemail.com wrote:Hi
if have simple macro defined this way:
#define M_OPplus( classname ) typedef classname operator+(const
classname& rhs);
and a template class :
template<typename X, typename Y>
class Test1
{
public:
double run();
M_OPplus( Test1<X,Y)^
the comma split up your argument into to parts
write
M_OPplus(( Test1<X,Y))
};
The compiler (VS2003) is complaining : warning C4002: too many actual
parameters for macro, . I think it is related to the comma in the
middle , the preprocessor may think that i am passing two parameters
to the macro.
Is it possible to fix it and does it conform with the C++ standart?
Many Thx
--
Thanks
Barry
<sw*****@googlemail.comwrote in message
news:11**********************@y42g2000hsy.googlegr oups.com...if have simple macro defined this way:
#define M_OPplus( classname ) typedef classname operator+(const
classname& rhs);
and a template class :
template<typename X, typename Y>
class Test1
{
public:
double run();
M_OPplus( Test1<X,Y)
};
The compiler (VS2003) is complaining : warning C4002: too many actual
parameters for macro, . I think it is related to the comma in the
middle , the preprocessor may think that i am passing two parameters
to the macro.Your correct.
Is it possible to fix it and does it conform with the C++ standart?Yes. You can use a little trick that involves passing a name of a macro
function to the M_OPplus macro which calls it to get at the tokens.
Something like this:
#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>
public:
double run();
M_OPplus(M_Test1);
};
See what I am getting at here?
"Barry" <dh*****@gmail.comwrote in message news:fc**********@aioe.org...sw*****@googlemail.com wrote:[...]
the comma split up your argument into to parts
write
M_OPplus(( Test1<X,Y))[...]
That introduces extra parenthesis which can muck up syntax. For instance:
This has a syntax error:
_______________
#define M_OPplus(classname) \
typedef classname \
operator+(const classname &rhs)
template<typename X, typename Y>
class Test1 {
public:
double run();
M_OPplus((Test1<X,Y>));
};
_______________
This does not:
_______________
#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>
public:
double run();
M_OPplus(M_Test1);
};
_______________
这篇关于MACRO和具有两个(或更多)参数的模板的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!