how can this be implement?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Lordaeron

    how can this be implement?

    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
  • Victor Bazarov

    #2
    Re: how can this be implement?

    "Lordaeron" <lordaeron@ms1. url.com.tw> wrote...[color=blue]
    > 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.[/color]

    No.
    [color=blue]
    > i think i am doing something like Resultset of Java[/color]

    Then don't do it. Or use Java.

    Victor


    Comment

    • John Harrison

      #3
      Re: how can this be implement?


      "Lordaeron" <lordaeron@ms1. url.com.tw> wrote in message
      news:5830ddda.0 307140206.5b34b 876@posting.goo gle.com...[color=blue]
      > 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[/color]

      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


      Comment

      • Glen Low

        #4
        Re: how can this be implement?

        > class data:public baseData[color=blue]
        > {
        > 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;[/color]

        [snipped]
        [color=blue]
        > i think i am doing something like Resultset of Java[/color]

        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.

        Comment

        Working...