重定义问题
现testprint.h在定义一个宏如下:
#define CPPUNIT_TEST_PRINT( testPrint ) \
CPPUNIT_NS::Test * pPrintTest=new CPPUNIT_NS::TestCaller <TestFixtureType> ( \
printDoc.getPrintName( #testPrint ))
在testprint.cpp中用到宏的时候:
CPPUNIT_TEST_PRINT(PrintTest1)
CPPUNIT_TEST_PRINT(PrintTest2)
CPPUNIT_TEST_PRINT(PrintTest3)
CPPUNIT_TEST_PRINT(PrintTest4)
会出现 error C2374: 'pPrintTest ' : redefinition; multiple initialization 的问题,因为我调用了4次
CPPUNIT_TEST_PRINT这个宏
请问怎么解决这个从定义问题呢?
大家帮忙指导下,谢谢!!!!!
[解决办法]
可以用宏的粘位宏##来生成不同的名字。
把你的宏改成
#define CPPUNIT_TEST_PRINT( testPrint ) \
CPPUNIT_NS::Test * ptestPrint##PrintTest=new CPPUNIT_NS::TestCaller <TestFixtureType> ( \
printDoc.getPrintName( #testPrint ))
[解决办法]
http://bbs.loveunix.net/viewthread.php?tid=20938
多一个9