消息生成错误,运算符 << 的模糊重载

message generation error, ambigious overload of operator <<

使用 nedtool/omnet(4.6)

生成消息 .cc 和头文件后出现以下错误

ambiguous overload for ‘operator<<’ (operand types are ‘std::ostream {aka std::basic_ostream}’ and ‘const std::basic_string’) CurrentNeighboursMessage_m.cc

这就是消息 class:CurrentNeighboursMessage.msg

cplusplus {{
 #include  <vector>
 #include <string>

 typedef std::vector<std::string> StringVector;
}}

    class noncobject StringVector;

    packet CurrentNeighboursMessage {
        StringVector currentNeighbours;
    }

生成的错误对应代码CurrentNeighboursMessage_m.cc:

此行错误:

out << *it;

  // operator<< for std::vector<T>
    template<typename T, typename A>
    inline std::ostream& operator<<(std::ostream& out, const std::vector<T,A>& vec)
    {
        out.put('{');
        for(typename std::vector<T,A>::const_iterator it = vec.begin(); it != vec.end(); ++it)
        {
            if (it != vec.begin()) {
                out.put(','); out.put(' ');
            }

            out << *it; 
        }
        out.put('}');

        char buf[32];
        sprintf(buf, " (size=%u)", (unsigned int)vec.size());
        out.write(buf, strlen(buf));
        return out;
    }

有人知道解决方案吗?

在以下位置找到了解决方案:https://groups.google.com/forum/#!msg/omnetpp/9Cw6F6ws_pc/isW42Rh0WG4J

要么不使用 typedef,要么使用这个解决方法:

cplusplus {{
#include  <vector>
#include <string>
//workaround
typedef std::string MyString;

inline std::ostream & operator << (std::ostream & os, const MyString & s) {
        std::operator<<(os, s);        
        return os;
}
typedef std::vector<MyString> StringVector;

}}
class noncobject StringVector;
packet CurrentNeighboursMessage {
    StringVector currentNeighbours;
}