这个C ++代码构造意味着什么?

时间:2013-06-20 17:31:29

标签: c++ data-distribution-service opensplice

我找到了以下代码(自动生成,但它没有编译),现在我想知道这意味着什么:

template<> struct topic_type_support<UnboundedStringWithKey> 
{            
    typedef UnboundedStringWithKey##TypeSupport type;                
};

有些人指出##是用于宏的,实际上代码是在宏中。我没有意识到这一点,并试图直接将其放入代码中以获得更清晰的错误消息。最初的宏是:

#define REGISTER_TOPIC_TRAITS(TOPIC)                    \
namespace dds { namespace topic {                    \
template<> struct topic_type_support<TOPIC> {            \
    typedef TOPIC##TypeSupport type;                \
};                                \
template<> struct is_topic_type<TOPIC> { enum {value = 1 }; };    \
template<> struct topic_type_name<TOPIC> {            \
    static std::string value() {                    \
        static topic_type_support<TOPIC>::type ts;            \
        return ts.get_type_name();                    \
    }                                \
};                                \
} }  

原始编译器错误是:语法错误:缺少';'在标识符'type'之前

我手动插入宏并应用##:

template<> struct topic_type_support<UnboundedStringWithKey> 
{            
    typedef UnboundedStringWithKeyTypeSupport type;                
}; 

但它直接在typedef中写道:缺少';'在标识符'type'之前(编译器是安装了SP1的VS2010)

有人能告诉我吗? (代码由OpenSplice的idlpp.exe生成)

原因现在很明显(我忘记了idl中的#pragma keylist条目) - 没有生成UnboundedStringWithKeyTypeSupport。但这是一个不同的问题。

此致 托拜厄斯

0 个答案:

没有答案
相关问题