When is this kind of tempo deleted?

D

doublemaster007

class Foo;

main{
Foo(); //at ; or end of main?

Foo &x =Foo() //at the end of main right?

Foo x = Foo(5) // This doesnt call copy constructor.. strange!

Foo x = Foo (6,7,8) // Does this call copy constrcutor?
 
V

Victor Bazarov

class Foo;

class Foo {};

int main() {
Foo(); //at ; or end of main?

Nope. Right there at the semicolon.
Foo &x =Foo() //at the end of main right?

Illegal code. A reference to non-const cannot be initialised with a
temporary. A semicolon is missing.
Foo x = Foo(5) // This doesnt call copy constructor.. strange!

Illegal code: a semicolon is missing. 'Foo' doesn't have a constructor
that takes an 'int' argument.

The compiler is allowed to omit copy-construction, but it has to be
accessible (as if it's used).
Foo x = Foo (6,7,8) // Does this call copy constrcutor?

Same thing: no semicolon, no constructor with three arguments. Again,
the same thing: no copy construction is necessary

Learn to post real code.

V
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,161
Messages
2,570,892
Members
47,429
Latest member
JacelynKit

Latest Threads

Top