N
Nephi Immortal
Why do C++ Compiler generates an error to report nonstandard extension? Func() and Func2() do the sequence by putting data into stack and pop them out.
Sequence:
Call Func()
Call Constructor
Call Copy Constructor
Call Destructor
Call Func2() as Data is a reference after copy constructor is created.
Call Func2() again and uses the same reference.
Call more deep functions until to the end.
Return back to Func()
Call Copy Constructor
Call Destructor
Return from Func() to main().
‘x’ has data after copy constructor was done.
The reference is used to avoid to allocate more temporary memory and more numbers of copy constructors are reduced.
main.cpp(1383): warning C4239: nonstandard extension used : 'argument' : conversion from 'Data' to 'Data &'
struct Data
{
Data() {}
~Data() {}
Data( Data const& r ) {}
int array_[ 8 ];
};
Data Func()
{
Data temp;
return temp;
}
Data &Func2( Data &d )
{
return d;
}
int main()
{
Data x = Func2( Func2( Func() ) );
return 0;
}
Sequence:
Call Func()
Call Constructor
Call Copy Constructor
Call Destructor
Call Func2() as Data is a reference after copy constructor is created.
Call Func2() again and uses the same reference.
Call more deep functions until to the end.
Return back to Func()
Call Copy Constructor
Call Destructor
Return from Func() to main().
‘x’ has data after copy constructor was done.
The reference is used to avoid to allocate more temporary memory and more numbers of copy constructors are reduced.
main.cpp(1383): warning C4239: nonstandard extension used : 'argument' : conversion from 'Data' to 'Data &'
struct Data
{
Data() {}
~Data() {}
Data( Data const& r ) {}
int array_[ 8 ];
};
Data Func()
{
Data temp;
return temp;
}
Data &Func2( Data &d )
{
return d;
}
int main()
{
Data x = Func2( Func2( Func() ) );
return 0;
}