请就指针以及值的转换和分配提供一些建议。
我有这个修复类定义:(由 gsoap 生成)
class LibClass
{
public:
std::string *email; // pointer
int landId; // no pointer
// (....) much more
}
在一个单独的函数中,我将数据库(informix)中的数据分配给上面的类成员。
(...) // just database connection
// The following is informix interface related stuff
ITRow *row;
// define one time this conversions interface
ITConversions *c;
// placeholder for all string types, temporary data container
ITString its("");
ITString colname;
// read result from executed query
while ( row = query.NextRow() ) {
LibClass *ki = new LibClass;
ki->email = new (string);
//ki->landId = new (int); // obviously : error: invalid conversion from 'int*' to 'int'
// I tried :
// invent a new instance
LibClass rki;
//rki = &ki;
//rki.x = 9;
// this is okay but how to bring ki and rki together,
int *a = new int;
rki.x = *a;
// And for understanding, here's what comes next - It seams as i have to hardcode all 30 DB fields... but thats okay for now.
colname="email";
ITValue *v = row->Column( colname );
v->QueryInterface(ITConversionsIID, (void **) &c);
c->ConvertTo( its );
*( ki->email ) = string(its.Data()); // THE DATA TRANSFER - assignment
v->Release();
} // while end
编辑我无法继续这样做,所以我不能批准这些建议,但只想在这里关闭,所以我接受最详细的答案。谢谢大家。