how can this be implement?

L

Lordaeron

class data:public baseData
{
public:
int aaa;
char bbb[3];
int ccc;
}
now i want a function something like
get(1) return values of aaa;
get(2) return values of bbb;
set(1,30) set the values of aaa to 30;
and because the data class may have different content,
and i think, i don't want to write N times of get and set, the
data may have data1, data2 .... etc, so , is there anyway that
can easier to implement.
i think i am doing something like Resultset of Java
 
V

Victor Bazarov

Lordaeron said:
class data:public baseData
{
public:
int aaa;
char bbb[3];
int ccc;
}
now i want a function something like
get(1) return values of aaa;
get(2) return values of bbb;
set(1,30) set the values of aaa to 30;
and because the data class may have different content,
and i think, i don't want to write N times of get and set, the
data may have data1, data2 .... etc, so , is there anyway that
can easier to implement.
No.

i think i am doing something like Resultset of Java

Then don't do it. Or use Java.

Victor
 
J

John Harrison

Lordaeron said:
class data:public baseData
{
public:
int aaa;
char bbb[3];
int ccc;
}
now i want a function something like
get(1) return values of aaa;
get(2) return values of bbb;
set(1,30) set the values of aaa to 30;
and because the data class may have different content,
and i think, i don't want to write N times of get and set, the
data may have data1, data2 .... etc, so , is there anyway that
can easier to implement.
i think i am doing something like Resultset of Java

You would have to derive all your data types from a common base class. Then
you'd probably want to add a smart pointer class to handle the memory
allocation. And you'd need to do RTTI to get at the actual underlying data.

It's a nightmare, don't do it, or do it in Java. Don't fight the language.

john
 
G

Glen Low

class data:public baseData
{
public:
int aaa;
char bbb[3];
int ccc;
}
now i want a function something like
get(1) return values of aaa;
get(2) return values of bbb;
set(1,30) set the values of aaa to 30;
[snipped]

i think i am doing something like Resultset of Java

If you can be happy with declaring data that you don't know the type
of, like in an ADO Recordset, you may want to try boost::any, see
http://www.boost.org or http://www.boost.org/doc/html/ch01s02.html.

Then you can say
typedef boost::any data [n]; // for fixed number of fields, or
typedef std::vector <boost::any> data; // for variable number of
fields.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,576
Members
45,054
Latest member
LucyCarper

Latest Threads

Top