how can this be implement?

Discussion in 'C++' started by Lordaeron, Jul 14, 2003.

  1. Lordaeron

    Lordaeron Guest

    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
     
    Lordaeron, Jul 14, 2003
    #1
    1. Advertising

  2. "Lordaeron" <> wrote...
    > 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
     
    Victor Bazarov, Jul 14, 2003
    #2
    1. Advertising

  3. "Lordaeron" <> wrote in message
    news:...
    > 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
     
    John Harrison, Jul 14, 2003
    #3
  4. Lordaeron

    Glen Low Guest

    > 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.
     
    Glen Low, Jul 15, 2003
    #4
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Oleg
    Replies:
    5
    Views:
    2,467
    Ray Andraka
    Feb 18, 2004
  2. =?Utf-8?B?ZVhzZXJhcGg=?=

    How can I implement the "Pushing" mode in Asp.Net application

    =?Utf-8?B?ZVhzZXJhcGg=?=, Nov 19, 2004, in forum: ASP .Net
    Replies:
    6
    Views:
    546
    bruce barker
    Nov 22, 2004
  3. ~Maheshkumar.R
    Replies:
    4
    Views:
    991
    Kareem Mostafa
    Mar 30, 2005
  4. beau
    Replies:
    2
    Views:
    317
    E.C. B├Ąck
    Aug 30, 2003
  5. Steve Jasper
    Replies:
    5
    Views:
    1,323
    Steve Jasper
    Nov 20, 2003
Loading...

Share This Page