在Corba中,我有一个类似这样的结构:
module XYZ {
typedef string AttributeName;
struct AttributeColumn {
AttributeName name; // Column attribute name
any data; // Column attribute value
};
typedef sequence <AttributeColumn> AttributeTable;
}
它包含来自相应Sqlite数据库表的值,该表具有以下字段:
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循环中的最后两行,那么代码就会编译,但它会崩溃。因此,不知何故,将";name";字段也不能正常工作。
试试这个:
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需要是相同类型的数据。