By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
434,701 Members | 2,021 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 434,701 IT Pros & Developers. It's quick & easy.

STL & Copy constructor..help

P: n/a
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
Share this Question
Share on Google+
3 Replies


P: n/a
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

P: n/a

"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

P: n/a
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 discussion thread is closed

Replies have been disabled for this discussion.