| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 622 人关注过本帖
标题:一个GCC正确,VC6编译错误的实例
只看楼主 加入收藏
vfdff
Rank: 6Rank: 6
等 级:侠之大者
威 望:8
帖 子:2172
专家分:425
注 册:2005-7-15
结帖率:79.17%
收藏
 问题点数:0 回复次数:1 
一个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理解的不一样?
搜索更多相关主题的帖子: 编译 GCC 实例 
2010-07-13 00:23
vfdff
Rank: 6Rank: 6
等 级:侠之大者
威 望:8
帖 子:2172
专家分:425
注 册:2005-7-15
收藏
得分:0 
将类名Test改为其他就可

~~~~~~~~~~~~~~~好好学习~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2010-07-14 00:30
快速回复:一个GCC正确,VC6编译错误的实例
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.016295 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved