This is the mail archive of the gcc-help@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

copy ctor not called


Hi,

Consider a class with a copy constructor:

class A
{
public:
  A(int i) : m_i(i) 
  {
    cout << "A(int i)" << endl;
  }

  A(const A &a)
  {
    cout << "A(const A &a)" << endl;
    m_i = a.i();
  }

  int i() { return m_i; }

private:
  int m_i;
};

now if I do something like:
A a = 2;
the output should be:
A(int i)
A(const A &a)
the actual output is:
A(int i)

Now, I understand that gcc optimizes away the copy constructor and interprets
the code as:
A a(2);

However, is there a way to force gcc to use the copy constructor?

best,
Jeroen

P.S.: I'm not on the list.
-- 
Kile -- KDE Integrated LaTeX Environment
http://kile.sourceforge.net


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]