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);
	}
	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);
	}
예제 #3
0
파일: spline.cpp 프로젝트: garinh/cs
float csBSpline::GetInterpolatedDimension (int dim) const
{
  float *p = &points[dim * num_points];
  float val = 0;
  int j;
  for (j = -2; j <= 1; j++)
  {
    // @@@ Not very efficient but it will do for now...
    // We would need to cache p[-1] and p[-2]
    float pp;
    int id = idx + j + 1;
    if (id == -1)
      pp = p[0] - (p[1] - p[0]);
    else if (id == -2)
      pp = p[0] - 2 * (p[1] - p[0]);
    else if (id >= num_points)
      pp = p[num_points - 1] - (p[num_points - 2] - p[num_points - 1]);
    else
      pp = p[id];
    val += BaseFunction (j, t) * pp;
  }

  return val;
}