예제 #1
0
//some code block
int main()
{
   BaseClass* p = new BaseClass( BaseClass( BaseClass( BaseClass( BaseClass( 1 ) ) ) ) );
   std::cout << "value=" << p->getValue() << std::endl;

   // BaseClass a; //, b, c;

   // wont compile
   /*
   if( (a = *p).increment())
      ;*/

   Derived d( 10 );
   std::cout << "value=" << d.getValue() << std::endl;
   *p = d;
   std::cout << "value=" << p->getValue() << std::endl;

   std::cout << "testing virtual function access..." << std::endl;
   p->f();                                        // OK, calls BaseClass::f()

   BaseClass* q = &d;
   q->f();                                        // OK because BaseClass::f() is public, and vptr goes to Derived::f()

   // wont compile
   /*
   Derived* t = &d;
   t->f(); Derived::f() is private */

   delete p;

   return 0;
   /*
      const A a1;
      A a2( a1 );
      return 0;*/
}
예제 #2
0
파일: main.cpp 프로젝트: Zingam/PureCpp
void main()
{
    std::cout << "Creating a BaseClass object:" << std::endl;
    BaseClass baseClass(1);

    std::cout << std::endl
              << "Testing object Id: "
              << baseClass.getId() << std::endl;

    std::cout << std::endl
                << "Re-initializing the BaseClass object:" << std::endl;
    baseClass = BaseClass(2);

    std::cout << std::endl
              << "Testing object Id: "
              << baseClass.getId() << std::endl;

    std::cout << "\nAuto-destroying the object on exit:" << std::endl << std:: endl;
}
예제 #3
0
////////////////////// Constructors //////////////////////
BaseClassI* BaseClassI::NewBaseClass()
{
	return new BaseClassCPP(gcnew BaseClass());
}