void SomeMethod() {
		// Construction from derived std::auto_ptr works...
		std::auto_ptr<Derived> dptr1 (new Derived(1));
		std::auto_ptr<Base> bptrConstructed (dptr1);

		// Assignment from derived std::auto_ptr too...
		std::auto_ptr<Derived> dptr2 (new Derived(2));
		std::auto_ptr<Base> bptrAssigned;
		bptrAssigned = dptr2;

#if 0
		// ...BUT initializers are ambiguous
		std::auto_ptr<Derived> dptr3 (new Derived(3));
		std::auto_ptr<Base> bptrInitialized = dptr3;

		// ...AND so are function arguments
		std::auto_ptr<Derived> dptr4 (new Derived(4));
		BaseFunction(dptr4);

		// conversion from ‘std::auto_ptr<Derived>’ to ‘std::auto_ptr<Base>’ is ambiguous
		// candidates are: 
		// std::auto_ptr<Derived>::operator std::auto_ptr<Base>()
		// std::auto_ptr<Base>::auto_ptr(std::auto_ptr<Derived>&) 
#endif

		// A static cast is a workaround, but not what I am
		// looking for in this case...want it to be implicit
		std::auto_ptr<Derived> dptr5 (new Derived(5));
		std::auto_ptr<Base> bptrInitializedStaticCast = 
			static_cast< std::auto_ptr<Base> >(dptr5);
	}
Example #2
0
TEST(UnitTestBoost, testUnit)
{
  {  
    double* d = new double;
    std::shared_ptr<double> dptr(d);

    ASSERT_EQ( dptr.get(), d);

    double* d2 = new double[1];
    boost::shared_array<double> dptr2(d2);

    ASSERT_EQ( dptr2.get(), d2);
  }
  
  ci_string s("This is a test");

  ASSERT_TRUE( s == "this is a test" );
}
	void SomeMethod() {
		// Construction from derived std::tr1::shared_ptr works...
		std::tr1::shared_ptr<Derived> dptr1 (new Derived(1));
		std::tr1::shared_ptr<Base> bptrConstructed (dptr1);
 
		// Assignment from derived std::tr1::shared_ptr too...
		std::tr1::shared_ptr<Derived> dptr2 (new Derived(2));
		std::tr1::shared_ptr<Base> bptrAssigned;
		bptrAssigned = dptr2;
 
		// Initializers work for shared pointers (unlike std::auto_ptr)
		std::tr1::shared_ptr<Derived> dptr3 (new Derived(3));
		std::tr1::shared_ptr<Base> bptrInitialized = dptr3;
 
		// ...AND function arguments work too (unlike std::auto_ptr)
		std::tr1::shared_ptr<Derived> dptr4 (new Derived(4));
		BaseFunction(dptr4);
	}