我有以下继承:
Size_(基类) ---->Size2_ -------> Size3_
当我调用构造函数时:
Size3_<int> a(2,2,1);
Size3_<int> b(3,3,1);
Size3_<double> c(1,1,0);
Size3_<double> out=(Size3_<double>(b-a))
CPPUNIT_ASSERT(out==c);
我收到以下编译器问题(g++):
SteerableTests.cpp: In member function ‘void SteerableTests::testsize3()’:
SteerableTests.cpp:22:34: error: call of overloaded ‘Size3_(Size3_<int>)’ is ambiguous
SteerableTests.cpp:22:34: note: candidates are:
Size3.h:107:2: note: Size3_<Tp>::Size3_(const cv::Size_<_Tp>&) [with Tp = double]
Size3.h:105:2: note: Size3_<Tp>::Size3_(const Size2_<Tp>&) [with Tp = double]
Size3.h:100:2: note: Size3_<Tp>::Size3_(const Size3_<Tp>&) [with Tp = double, Size3_<Tp> = Size3_<double>]
因此继承的对象也被视为基础对象。如何告诉g ++编译器选择继承阶段最低的?在 Visual Studio 中,它可以工作。
P/S:这里是构造函数列表:
Size3_(const Size3_& sz);
Size3_(const Size2_<Tp>& sz2);
Size3_(const Size_<Tp> & cvsz);