public inbox for gcc-help@gcc.gnu.org
 help / color / mirror / Atom feed
* copy ctor not called
@ 2005-07-02 18:21 Jeroen Wijnhout
  2005-07-02 19:17 ` Travis Spencer
  2005-07-03 12:27 ` Dirk Jagdmann
  0 siblings, 2 replies; 9+ messages in thread
From: Jeroen Wijnhout @ 2005-07-02 18:21 UTC (permalink / raw)
  To: gcc-help

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

^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2005-07-08 18:26 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2005-07-02 18:21 copy ctor not called Jeroen Wijnhout
2005-07-02 19:17 ` Travis Spencer
2005-07-03  8:15   ` Jeroen Wijnhout
2005-07-03 12:27 ` Dirk Jagdmann
2005-07-03 13:44   ` Jeroen Wijnhout
2005-07-05 14:10     ` Eljay Love-Jensen
2005-07-07 11:45       ` Jeroen Wijnhout
2005-07-07 12:02       ` Eljay Love-Jensen
2005-07-08 18:26         ` Jeroen Wijnhout

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).