operator overloading & STL

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

    operator overloading & STL

    Basic question: I am using STL for the first time, and I want to put
    the following class into a vector. What member functions/overloaded
    operators do I have to include? In general, when using STL, how do I
    answer this question?

    //*************** ***
    class cStockPrice
    {
    private:
    string date;
    float price;
    public:
    cStockPrice() : date("NA"), close(0)
    { }
    void getPrice(string tmpDate, float clse)
    { date=tmpDate;
    close=clse;
    }
    }; //end of cStockPrice
  • David B. Held

    #2
    Re: operator overloading & STL

    "solartimba " <kaferro@hotmai l.com> wrote in message
    news:1a7f7e51.0 310111515.2fd7f e9a@posting.goo gle.com...[color=blue]
    > Basic question: I am using STL for the first time, and I want to
    > put the following class into a vector. What member
    > functions/overloaded operators do I have to include?[/color]

    Elements of std::vector<> just have to be default constructible
    and copyable. You define a default c'tor, and the compiler-
    generated copy c'tor will work just fine for your class, so it
    should work as is.
    [color=blue]
    > In general, when using STL, how do I answer this question?
    > [...][/color]

    Use the table which states requirements on T for various
    containers.

    Dave



    ---
    Outgoing mail is certified Virus Free.
    Checked by AVG anti-virus system (http://www.grisoft.com).
    Version: 6.0.521 / Virus Database: 319 - Release Date: 9/23/2003


    Comment

    • Rolf Magnus

      #3
      Re: operator overloading &amp; STL

      solartimba wrote:
      [color=blue]
      > Basic question: I am using STL for the first time, and I want to put
      > the following class into a vector. What member functions/overloaded
      > operators do I have to include?[/color]

      None. Your class just has to be copyable, which your example below is.
      [color=blue]
      > In general, when using STL, how do I answer this question?[/color]

      Get a good book about it.
      [color=blue]
      > //*************** ***
      > class cStockPrice
      > {
      > private:
      > string date;
      > float price;[/color]

      Wasn't that float member meant to be named 'close'?
      [color=blue]
      > public:
      > cStockPrice() : date("NA"), close(0)
      > { }
      > void getPrice(string tmpDate, float clse)
      > { date=tmpDate;
      > close=clse;
      > }
      > }; //end of cStockPrice[/color]

      Comment

      • Moonlit

        #4
        Re: operator overloading &amp; STL


        "solartimba " <kaferro@hotmai l.com> wrote in message
        news:1a7f7e51.0 310111515.2fd7f e9a@posting.goo gle.com...[color=blue]
        > Basic question: I am using STL for the first time, and I want to put
        > the following class into a vector. What member functions/overloaded
        > operators do I have to include? In general, when using STL, how do I
        > answer this question?
        >
        > //*************** ***
        > class cStockPrice
        > {
        > private:
        > string date;
        > float price;
        > public:
        > cStockPrice() : date("NA"), close(0)
        > { }
        > void getPrice(string tmpDate, float clse)
        > { date=tmpDate;
        > close=clse;
        > }
        > }; //end of cStockPrice[/color]

        Questions answered in other replies. However to look up what the STL expects
        and what you can do with it see;



        /* some things like Hashmaps seems to be no longer supported with g++ it
        seems. */

        Regards, Ron AF Greve.









        Comment

        Working...