问题描述
module XYZ {
typedef string AttributeName;
struct AttributeColumn {
AttributeName name; // Column attribute name
any data; // Column attribute value
};
typedef sequence <AttributeColumn> AttributeTable;
}
ABC_Name VARCHAR NOT NULL UNIQUE
我想将这些值复制到C ++结构中,该结构包含以下内容:
namespace DEF {
typedef std::string AttributeName;
typedef std::vector<std::string> StringCol;
struct AttributeColumn {
AttributeName name; // Column attribute name
StringCol str; // Column values if string
};
typedef std::vector<AttributeColumn> AttributeTable;
}
这是我的尝试:
XYZ::AttributeTable & xyz_table = getAttributeTable (); // This gives me the table containing the data from the database.
int rows = getLength ( xyz_table ); // This gives me the number of rows in the database.
DEF::AttributeTable def_table;
for (int i=0;i<rows;i++) {
def_table[i].name = xyz_table[i].name;
std::cout << def_table[i].name << std::endl;
xyz_table[i].data >>= def_table[i].str;
std::cout << def_table[i].str << std::endl;
}
ERROR: 1> error: no match for ‘operator>>=’ (operand types are ‘CORBA::Any’ and ‘DEF::StringCol’ {aka ‘std::vector<std::basic_string<char> >’})
如果我注释掉for循环的最后两行,则代码会编译,但会崩溃。 因此,以某种方式,复制到def_table中的“名称”字段也无法正常工作。
解决方法
试试这个:
namespace DEF {
typedef std::string AttributeName;
typedef std::vector<std::string> StringCol;
struct AttributeColumn {
AttributeName name; // Column attribute name
CORBA::Any str; // Column values if string
};
typedef std::vector<AttributeColumn> AttributeTable;
};
因为 str 需要是相同类型的数据。