_.cpp is updated for more options. Also a test is done on implicite copy constructor generation for a derived class.
85 lines
1.5 KiB
C++
85 lines
1.5 KiB
C++
/* Check cf5-opt.vim defs.
|
|
VIM: let g:lcppflags="-std=c++11 -O2 -pthread"
|
|
VIM-: let g:cppflags=g:Iboost.g:Itbb
|
|
VIM-: let g:ldflags=g:Lboost.g:Ltbb.g:tbbmalloc.g:tbbmproxy
|
|
VIM-: let g:ldlibpath=g:boostld.g:tbbld
|
|
VIM-: let g:cf5output=0
|
|
*/
|
|
|
|
/*
|
|
* Conclusion:
|
|
* Per C++ standard since Son doesn't have explicitely defined copy
|
|
* assignement operator the an implicite one is generated which call
|
|
* Base::operatro = () as a result overriden operator in the Son is not
|
|
* called.
|
|
*/
|
|
|
|
#include <iostream>
|
|
#include <exception>
|
|
|
|
class Base
|
|
{
|
|
public:
|
|
int b;
|
|
|
|
virtual Base &operator=(const Base & o)
|
|
{ std::cout << "Base" << std::endl; b=o.b; return *this; };
|
|
};
|
|
|
|
class Derived : public Base
|
|
{
|
|
public:
|
|
int d;
|
|
|
|
virtual Base &operator=(const Base &)
|
|
{ std::cout << "Derived 1" << std::endl; return *this;};
|
|
|
|
virtual Derived &operator=(const Derived &)
|
|
{ std::cout << "Derived 2" << std::endl; return *this;};
|
|
};
|
|
|
|
class Son : public Base
|
|
{
|
|
public:
|
|
int d;
|
|
|
|
virtual Base &operator=(const Base &)
|
|
{ std::cout << "Son" << std::endl; return *this;};
|
|
|
|
};
|
|
|
|
|
|
int main ( void )
|
|
{try{
|
|
|
|
Derived d1, d2;
|
|
d1.b = 0;
|
|
d2.b = 1;
|
|
d1.d = 0;
|
|
d2.d = 1;
|
|
Base * b1 = &d1;
|
|
Base * b2 = &d2;
|
|
*b1 = *b2;
|
|
std::cout << d1.b << d1.d << std::endl;
|
|
|
|
d1 = d2;
|
|
|
|
Son s1, s2;
|
|
s1 = s2;
|
|
|
|
return 0;
|
|
}
|
|
catch ( const std::exception& e )
|
|
{
|
|
std::cerr << std::endl
|
|
<< "std::exception(\"" << e.what() << "\")." << std::endl;
|
|
return 2;
|
|
}
|
|
catch ( ... )
|
|
{
|
|
std::cerr << std::endl
|
|
<< "unknown exception." << std::endl;
|
|
return 1;
|
|
}}
|
|
|