473,407 Members | 2,314 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,407 software developers and data experts.

STL & Copy constructor..help

Hello All,

I get an unexpected behaviour for this

class D{

/*something*/
};

class B
{
D *ptr;
/* something more */
};

class A
{
vector<B> Blist;

};
in some function of class A
for(i=0;i<n;i++)
{
B obj;
Blist.push_back(obj); //throws an exception
}

i have defined copy constructors for all the classes and used explicit
keyword also in the declaration

I think STL makes a copy using this copy constrcutor to store internally.Plz
throw some light

Thaanx in advance
Rgds,
Naren.

Jul 19 '05 #1
3 4270
Naren wrote:
i have defined copy constructors for all the classes and used explicit
keyword also in the declaration


Comment 1) Are the assignment operator '=' methods for classes D and B
implemented correctly?

Comment 2) There is not enough information in your original post to
determine the actual problem. You really need to post the source code
for a short, complete, compilable program that excatly demonstrates the
problem you're describing. If we don't have some actual code to look at,
it's anyone's guess as to what the actual problem(s) might be.

--
Jim

To reply by email, remove "link" and change "now.here" to "yahoo"
jfischer_link5809{at}now.here.com
Jul 19 '05 #2

"Naren" <na*************@in.bosch.com> wrote in message
news:bi**********@ns2.fe.internet.bosch.com...
Hello All,

I get an unexpected behaviour for this

class D{

/*something*/
};

class B
{
D *ptr;
/* something more */
};

class A
{
vector<B> Blist;

};
in some function of class A
for(i=0;i<n;i++)
{
B obj;
Blist.push_back(obj); //throws an exception
}

i have defined copy constructors for all the classes and used explicit
keyword also in the declaration

I think STL makes a copy using this copy constrcutor to store internally.Plz throw some light
Yes the STL makes a copy using your copy constructor.

If you have defined your copy constructors correctly then this wouldn't be a
problem. Please post the code you are really using.

Thaanx in advance
Rgds,
Naren.


john
Jul 19 '05 #3
Naren wrote:
Hello All,

I get an unexpected behaviour for this

class D{

/*something*/
};

class B
{
D *ptr;
/* something more */
};

class A
{
vector<B> Blist;

};
in some function of class A
for(i=0;i<n;i++)
{
B obj;
Blist.push_back(obj); //throws an exception
What exception?
}

i have defined copy constructors for all the classes and used explicit
keyword also in the declaration
I don't see any copy constructors.

I think STL makes a copy using this copy constrcutor to store internally.Plz
throw some light


The standard containers may copy using copy constructors or copy
assignment. Objects you store in them must support both operations with
the usual semantics.

Your problem is not apparent from what you posted. Please post a minimal
complete program that demonstrates the problem. You should *always* do
this when asking a question here.

-Kevin
--
My email address is valid, but changes periodically.
To contact me please use the address from a recent posting.

Jul 19 '05 #4

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

Similar topics

25
by: Victor Bazarov | last post by:
In the project I'm maintaining I've seen two distinct techniques used for returning an object from a function. One is AType function(AType const& arg) { AType retval(arg); // or default...
10
by: ambar.shome | last post by:
Dear All, Whats the difference between a copy constructor and assignment operator. We can assign the values of member variables of one object to another object of same type using both of them....
5
by: Evgeny | last post by:
Hi, all! I try to convert my existing code written in VC6 to VC7 and have some problem with stl auto pointer template. class CColumn; #include <memory> typedef auto_ptr<CMyBase> CMyBasePtr; ...
10
by: utab | last post by:
Dear all, Can somebody direct me to some resources on the subject or explain the details in brief? I checked the FAQ but could not find or maybe missed. Regards,
8
by: toton | last post by:
HI, One more small doubt from today's mail. I have certain function which returns a pointer (sometimes a const pointer from a const member function). And certain member function needs reference...
7
by: John Nagle | last post by:
I've been parsing existing HTML with BeautifulSoup, and occasionally hit content which has something like "Design & Advertising", that is, an "&" instead of an "&amp;". Is there some way I can get...
3
by: RainBow | last post by:
I understand that a compiler synthesises a default constructor if none is provided by the user ( of course depending on the situation if synthesis of such c'tor is actually needed in the program...
1
by: developereo | last post by:
Hi folks, Can somebody shed some light on this problem? class Interface { protected: Interface() { ...} virtual ~Interface() { ... } public:
5
by: * Tong * | last post by:
Hi, I couldn't figure out the answer myself about the default constructor -- does C++ create it by default? If yes, under what circumstances? Actually, I've found out the partial answer myself...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.