473,396 Members | 2,061 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

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
Jul 19 '05 #1
3 2846
"solartimba" <ka*****@hotmail.com> wrote in message
news:1a**************************@posting.google.c om...
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

---
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
Jul 19 '05 #2
solartimba wrote:
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'?
public:
cStockPrice() : date("NA"), close(0)
{ }
void getPrice(string tmpDate, float clse)
{ date=tmpDate;
close=clse;
}
}; //end of cStockPrice


Jul 19 '05 #3

"solartimba" <ka*****@hotmail.com> wrote in message
news:1a**************************@posting.google.c om...
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.



Jul 19 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

16
by: Edward Diener | last post by:
Is there a way to override the default processing of the assignment operator for one's own __value types ? I realize I can program my own Assign method, and provide that for end-users of my class,...
16
by: gorda | last post by:
Hello, I am playing around with operator overloading and inheritence, specifically overloading the + operator in the base class and its derived class. The structure is simple: the base class...
0
by: cppsks | last post by:
Hello. I posted a question regarding this yesterday. I came up with the following solution but I am a little hesistant as to this solution having any side-effects that I am not aware of. The...
6
by: sandSpiderX | last post by:
Hi, How do i use this definition of overloaded operator, T& operator*(T*); like struct X {}; X ox; X* px=&ox;
2
by: David Laub | last post by:
I know there is no C# exponentiation operator. But since the double class is sealed, there seems no way to add the operator override without creating a new class which uses containment (of a...
67
by: carlos | last post by:
Curious: Why wasnt a primitive exponentiation operator not added to C99? And, are there requests to do so in the next std revision? Justification for doing so: C and C++ are increasingly used...
2
by: Tom Smith | last post by:
I'm having difficulty with overloading ==, and it's making my brain melt - can you help...? What I want to have is: 1) A base class A with virtual operator== defined (no problem) 2) A class B...
3
by: karthik | last post by:
The * operator behaves in 2 different ways. It is used as the value at address operator as well as the multiplication operator. Does this mean * is overloaded in c?
3
by: y-man | last post by:
Hi, I am trying to get an overloaded operator to work inside the class it works on. The situation is something like this: main.cc: #include "object.hh" #include "somefile.hh" object obj,...
8
by: Wayne Shu | last post by:
Hi everyone, I am reading B.S. 's TC++PL (special edition). When I read chapter 11 Operator Overloading, I have two questions. 1. In subsection 11.2.2 paragraph 1, B.S. wrote "In particular,...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.