一个GCC正确,VC6编译错误的实例
程序代码:
//--- Hello, World! for CppUnit #include <iostream> #include <cppunit/TestRunner.h> #include <cppunit/TestResult.h> #include <cppunit/TestResultCollector.h> #include <cppunit/extensions/HelperMacros.h> #include <cppunit/BriefTestProgressListener.h> #include <cppunit/extensions/TestFactoryRegistry.h> class Test : public CPPUNIT_NS::TestCase { CPPUNIT_TEST_SUITE(Test); CPPUNIT_TEST(testHelloWorld); CPPUNIT_TEST_SUITE_END(); public: void setUp(void) {} void tearDown(void) {} protected: void testHelloWorld(void) { std::cout << "Hello, world!" << std::endl; } }; CPPUNIT_TEST_SUITE_REGISTRATION(Test); int main( int ac, char **av ) { //--- Create the event manager and test controller CPPUNIT_NS::TestResult controller; //--- Add a listener that colllects test result CPPUNIT_NS::TestResultCollector result; controller.addListener( &result ); //--- Add a listener that print dots as test run. CPPUNIT_NS::BriefTestProgressListener progress; controller.addListener( &progress ); //--- Add the top suite to the test runner CPPUNIT_NS::TestRunner runner; runner.addTest( CPPUNIT_NS::TestFactoryRegistry::getRegistry().makeTest() ); runner.run( controller ); return result.wasSuccessful() ? 0 : 1; }以上代码在linux下使用GCC能编译通过,但是使用VC6就不行了,说 CPPUNIT_TEST(testHelloWorld);这个的类型不一致:
>,void (__thiscall CppUnit::Test::*)(void),class Test &)' : cannot convert parameter 2 from 'void (__thiscall Test::*)(void)' to 'void (__thiscall CppUnit::Test::*)(void)'
Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
看了VC6和GCC理解的不一样?