Connecting Tech Pros Worldwide Forums | Help | Site Map

operator overloading & STL

solartimba
Guest
 
Posts: n/a
#1: Jul 19 '05
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
Guest
 
Posts: n/a
#2: Jul 19 '05

re: operator overloading & STL


"solartimba" <kaferro@hotmail.com> wrote in message
news:1a7f7e51.0310111515.2fd7fe9a@posting.google.c om...[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


Rolf Magnus
Guest
 
Posts: n/a
#3: Jul 19 '05

re: operator overloading & 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]

Moonlit
Guest
 
Posts: n/a
#4: Jul 19 '05

re: operator overloading & STL



"solartimba" <kaferro@hotmail.com> wrote in message
news:1a7f7e51.0310111515.2fd7fe9a@posting.google.c om...[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;

http://www.sgi.com/tech/stl/

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

Regards, Ron AF Greve.









Closed Thread