operator overloading & STL

S

solartimba

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
 
D

David B. Held

solartimba said:
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?

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.
In general, when using STL, how do I answer this question?
[...]

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

Dave
 
R

Rolf Magnus

solartimba said:
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?

None. Your class just has to be copyable, which your example below is.
In general, when using STL, how do I answer this question?

Get a good book about it.
//******************
class cStockPrice
{
private:
string date;
float price;

Wasn't that float member meant to be named 'close'?
 
M

Moonlit

solartimba said:
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

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.
 

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
474,145
Messages
2,570,824
Members
47,369
Latest member
FTMZ

Latest Threads

Top