473,769 Members | 2,331 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

STL & Copy constructor..he lp

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 4297
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_link58 09{at}now.here. com
Jul 19 '05 #2

"Naren" <na************ *@in.bosch.com> wrote in message
news:bi******** **@ns2.fe.inter net.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
2945
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 construction and then.. // some other processing and/or changing 'retval' return retval; }
10
10721
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. Then where is the difference?
5
4335
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; class CMyBase {
10
8562
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
2402
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 (or better a const reference). for eg, const PointRange* points = cc.points(ptAligned);
7
4628
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 BeautifulSoup to clean those up? There are various parsing options related to "&" handling, but none of them seem to do quite the right thing. If I write the BeautifulSoup parse tree back out with "prettify", the loose "&" is still in there. So...
3
2266
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 e.g if vptr is needed, default c'tor must be synthesised by compiler). In the class Temporary below, there is no reason why a compiler should synthesise a default c'tor. class Temporary {
1
327
by: developereo | last post by:
Hi folks, Can somebody shed some light on this problem? class Interface { protected: Interface() { ...} virtual ~Interface() { ... } public:
5
359
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 via trying the following code: ----------------------------------------- #include <string>
0
9589
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10222
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10050
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9999
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
7413
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6675
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5448
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3967
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2815
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.