Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/visual-studio-2008/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ Visual Studio-返回值失败时没有编译错误_C++_Visual Studio 2008 - Fatal编程技术网

C++ Visual Studio-返回值失败时没有编译错误

C++ Visual Studio-返回值失败时没有编译错误,c++,visual-studio-2008,C++,Visual Studio 2008,问题。 请参阅下面的代码。。。我缺少返回字段语句,并且在一些调试运行中没有发现它。我从来没有想过这样的东西会通过编译器而不会出错!为什么会这样 说明 我有一个解析器对象,它使用std::tr1::function接收构造时的翻译算法。转换从字符串转换为类型为TransportableMessage的对象,该对象由TMFields组成,可以容纳不同的类型。因此,无论如何,我创建了一个工厂函数来创建字段,因为字段的类型基于字符串(来自XML),虽然现在只有几个,但将来可能会有更多 tstring对象

问题。 请参阅下面的代码。。。我缺少
返回字段语句,并且在一些调试运行中没有发现它。我从来没有想过这样的东西会通过编译器而不会出错!为什么会这样

说明 我有一个解析器对象,它使用
std::tr1::function
接收构造时的翻译算法。转换从字符串转换为类型为
TransportableMessage
的对象,该对象由
TMFields
组成,可以容纳不同的类型。因此,无论如何,我创建了一个工厂函数来创建字段,因为字段的类型基于字符串(来自XML),虽然现在只有几个,但将来可能会有更多

tstring
对象是基于
UNICODE
的类型转换,基本上在一分钟内解析为
std::wstring
。另外,因为我使用的是VS2008
unique\u ptr
不存在,所以我将
std::auto\u ptr
隐藏在
ScopedPtr\u t
后面,以使升级更容易,从而更有可能发生

namespace arc
{
    namespace util
    {

        int internalTest()
        {
            std::cout << "Any error?" << std::endl;
        }

        ScopedPtr_T<TMField> TmFieldFactory( const tstring& name, const tstring& typeName, const tstring& value )
        {
            ScopedPtr_T<TMField> field;
            int a = internalTest();
            if( typeName == _T("int") || typeName == _T("long") )
            {
                field.reset( new TMNumericField( name, boost::lexical_cast<__int64>(value) ) );
            }
            else if( typeName == _T("string") )
            {
                field.reset( new TMStringField( name, value ) );
            }
            else if( typeName == _T("timestamp") )
            {
                field.reset( new TMTimeField( name, boost::lexical_cast<__int64>(value) ) );
            }
            else
            {
                std::string info( __FILE__ " :: " __FUNCTION__ " : Unrecognized TmField type ");
                std::string type( typeName.begin(), typeName.end() );
                info += type;
                throw ARC_Exception( info.c_str() );
            }
            return field; // I WAS MISSING THIS!
        }
    }
}

从函数体上掉下来而不返回某些内容不是错误,而是未定义的行为;参见6.3.3<代码>返回语句[stmt.return]§3:

从函数末尾流出相当于没有值的返回;这会导致值返回函数中出现未定义的行为


从函数体上掉下来而不返回某些内容不是错误,而是未定义的行为;参见6.3.3<代码>返回语句[stmt.return]§3:

从函数末尾流出相当于没有值的返回;这会导致值返回函数中出现未定义的行为


可能是因为您没有任何东西导致该模板的实例化?您有吗?@pwny-我很确定我实例化了该模板,但我添加了
internalTest
函数以将其从考虑范围中删除@柔印-我没有。我把音量调到了W4。由于库代码,无法使用WX。即使在W4上也没有提到丢失的返回。这个代码一定没有被编译过,因为我很确定这应该是一个错误。可能是重复的,可能是因为你没有任何东西导致该模板的实例化?你有吗?@pwny-我很确定我实例化了该模板好的,但我添加了
internalTest
函数,以将其从考虑范围中删除@柔印-我没有。我把音量调到了W4。由于库代码,无法使用WX。即使在W4上也没有提到丢失的返回。这个代码一定没有被编译,因为我很确定这应该是一个错误。可能是
SharedPtr_T<TransportableMessage> strToTmConvFunc_Default_Apc7_0(const std::string& tm_str)
{
    pugi::xml_document xmlDoc;
    if( false == xmlDoc.load( tm_str.c_str() ) )
    {
        ARC_LOG(LOG_WARN, "The passed TM object was malformed. %s", tm_str.c_str() );
        throw ARC_Exception( "Malformed Transportable Message XML" );
    }

    pugi::xml_node tmBase = xmlDoc.first_child();
    std::string xmlRootName( tmBase.name() );
    if( xmlRootName.compare("TM") != 0 )
    {
        ARC_LOG(LOG_WARN, "The passed TM object was malformed. %s", tm_str.c_str() );
        throw ARC_Exception( "Malformed Transportable Message XML" );
    }

    std::string tmname = tmBase.child("N").child_value();
    std::string entity = tmBase.child("E").child_value();
    ARC_LOG(LOG_INFO, "TM message received for parsing. TM name is %s", tmname.c_str() );

    tstring t_tmname( tmname.begin(), tmname.end() );
    SharedPtr_T<TransportableMessage> tm_obj( new TransportableMessage( t_tmname, 0 ) );

    pugi::xml_node fields = tmBase.child("FS");
    for( pugi::xml_node field = fields.first_child(); field; field = field.next_sibling("field") )
    {
        tm_obj->addField( arc::util::TmFieldFactory( field.child_value("N"), field.child_value("T"), field.child_value("V") ) );
    }

    return tm_obj;
}