Will Foo(Foo x){ } ever be called in C++? -


i have query regarding c++ syntax/construct : in scenario can following foo(foo x){} called? understand wont called initialization like, call copy constructor

foo a; foo x = a; or  foo x(a); 

not conversion of type argument passed of same type class

can't think of scenario on foo(foo x){} called, or dead code.

class foo {    public :     foo(foo x){  // notice not not copy constructor!!, intented make ordinary ctor taking same class object     }     foo(int x) : m_data(x){} private :   int m_data; }; 

have tried compile code?

error   1   error c2652: 'foo' : illegal copy constructor: first parameter must not 'foo'  main.cpp    5   1   nativeconsolesketchbook 

c++11 standard, 12.8.6:

a declaration of constructor class x ill-formed if first parameter of type (optionally cv-qualified) x , either there no other parameters or else other parameters have default arguments.


Comments

Popular posts from this blog

html5 - What is breaking my page when printing? -

c# - must be a non-abstract type with a public parameterless constructor in redis -

ajax - PHP/JSON Login script (Twitter style) not setting sessions -