Add New Class feature

Go To Last Post
4 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

When I create a new class using the "Add New Class" tool, select class and give it a name (eg. A), I get these lines in the header file:

private:
    A( const A&c );
    A& operator=( const A&c );

 

What do these lines actually do?

 

I have 2 classes (defined using Add New Class), and if I want to return class A from a function in class B, it throws an error because of these lines.

Error is: 

B.h:In file included from
B.cpp:from
A.h:In member function 'A B::getA()'
A.h:38:2: error: 'A::A(const A&)' is private
:A( const A&c );
:^
B.cpp:81:9: error: within this context
:return waveform;
:^
Error compiling

 

Goes away if I comment these lines out.

 

cheers
Paul

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

These are copy constructors (that's the google-worthy term). I'm not going to re-iterate much about these, but they basically means that you will not be able to copy objects of this class (through assignment, =, or construction)

:: Morten

 

(yes, I work for Atmel, yes, I do this in my spare time, now stop sending PMs)

 

The postings on this site are my own and do not represent Microchip’s positions, strategies, or opinions.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Ehhh. be very very careful of copy constructors!

Temporary objects are NOT your friend!!

 

I put the little buggars in private and leave them unimplemented so they cannot be called

Keith Vasilakes

Firmware engineer

Minnesota

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Thanks for the info.  Will do some research on copy constructors!