2014-12-05 27 views
-2

我试图做一个自定义列表,它有一个私人向量的实习生。C++不编译我的自定义数据类型,包括一个向量

但我总是得到这个错误消息,并不知道哪里开始寻找问题。我在我的项目中使用Qt,windows和“CONFIG + = C++ 11”。

...myPath\c++\bits\stl_construct.h:75: Error: call of overloaded 'myDataType()' is ambiguous 
    { ::new(static_cast<void*>(__p)) _T1(std::forward<_Args>(__args)...); } 
^

这个errormessage试图告诉我这里有什么?我应该从哪里开始看?

感谢您的任何提示。

编辑:构造函数列表:

/*********************************************************************** 
* Constructors and a Destructor 
* *********************************************************************/ 
datatype_collection::datatype_collection(){ 
    std::vector<datatype> erg (0); 
    m_datatype_list = erg; 
} 

datatype_collection::~datatype_collection(){ 
} 

的数据类型:

/*********************************************************************** 
* Constructors and a Destructor - Implemented because of the rule of 3 
* *********************************************************************/ 
datatype::datatype(float value) 
    : m_datatype(to_datatype(value)){ 
} 

datatype::datatype(int32_t value) 
    : m_datatype(value){ 
} 

fix_point::~fix_point(){ 
} 

EDIT2:有很多文本,但它不直接标记为错误:

...\mingw482_32\i686-w64-mingw32\include\c++\vector:62: In file included from 

.../mingw482_32/i686-w64-mingw32/include/c++/vector:62:0, 

...\QtCreator\bin\myFolder\datatype_collection.h:25: from ..\myFolder\datatype_collection.h:25, 

...\QtCreator\bin\myFolder\datatype_collection.cpp:1: from ..\myFolder\datatype_collection.cpp:1: 

...\mingw482_32\i686-w64-mingw32\include\c++\bits\stl_construct.h:-1: In instantiation of 'void std::_Construct(_T1*, _Args&& ...) [with _T1 = fix_point; _Args = {}]': 

...\mingw482_32\i686-w64-mingw32\include\c++\bits\stl_uninitialized.h:495: required from 'static void std::__uninitialized_default_n_1<_TrivialValueType>::__uninit_default_n(_ForwardIterator, _Size) [with _ForwardIterator = fix_point*; _Size = unsigned int; bool _TrivialValueType = false]' 

...\mingw482_32\i686-w64-mingw32\include\c++\bits\stl_uninitialized.h:544: required from 'void std::__uninitialized_default_n(_ForwardIterator, _Size) [with _ForwardIterator = fix_point*; _Size = unsigned int]' 

...\mingw482_32\i686-w64-mingw32\include\c++\bits\stl_uninitialized.h:605: required from 'void std::__uninitialized_default_n_a(_ForwardIterator, _Size, std::allocator<_Tp>&) [with _ForwardIterator = fix_point*; _Size = unsigned int; _Tp = fix_point]' 

...\mingw482_32\i686-w64-mingw32\include\c++\bits\stl_vector.h:1225: required from 'void std::vector<_Tp, _Alloc>::_M_default_initialize(std::vector<_Tp, _Alloc>::size_type) [with _Tp = fix_point; _Alloc = std::allocator<fix_point>; std::vector<_Tp, _Alloc>::size_type = unsigned int]' 

...\mingw482_32\i686-w64-mingw32\include\c++\bits\stl_vector.h:271: required from 'std::vector<_Tp, _Alloc>::vector(std::vector<_Tp, _Alloc>::size_type, const allocator_type&) [with _Tp = fix_point; _Alloc = std::allocator<fix_point>; std::vector<_Tp, _Alloc>::size_type = unsigned int; std::vector<_Tp, _Alloc>::allocator_type = std::allocator<fix_point>]' 

...\QtCreator\bin\Aufgabe2Punkt1\datatype_collection.cpp:8: required from here 

...\mingw482_32\i686-w64-mingw32\include\c++\bits\stl_construct.h:75: Error: call of overloaded 'datatype()' is ambiguous 
    { ::new(static_cast<void*>(__p)) _T1(std::forward<_Args>(__args)...); } 
    ^

...\mingw482_32\i686-w64-mingw32\include\c++\bits\stl_construct.h:75: candidates are: 

...\QtCreator\bin\myFolder\datatype_collection.h:24: In file included from ..\myFolder\datatype_collection.h:24:0, 

...\QtCreator\bin\myFolder\datatype_collection.cpp:1: from ..\myFolder\datatype_collection.cpp:1: 

...\QtCreator\bin\myFolder\datatype.hpp:48: datatype::datatype(int32_t) 
    datatype(int32_t value=0);   //constructor with default value 

...\QtCreator\bin\myFolder\fixpoint.hpp:47: datatype::datatype(float) 
    datatype(float value=0);   //constructor with default value 
    ^

更新: 我发现是什么原因造成的麻烦,但我不知道为什么它导致s的问题:

/**************************************************************** 
* overloading of the []-operator 
* *************************************************************/ 
const datatype& datatype_collection::operator[](int value) const{ //read-only 

    return m_datatype_list[value]; 
} 

此方法导致错误,如上所示。

+2

你重载你的构造函数含糊不清? – Columbo 2014-12-05 17:57:08

+0

如果没有真正看到导致错误的代码,它是不可能的。 – Galik 2014-12-05 17:59:07

+0

你为什么不直接向我们展示你的代码? – lpapp 2014-12-05 17:59:20

回答

2

通过Hi-Angel解决:

the problem is that you have two constructors with a default values. The call datatype() at the line 8 is ambiguous: which one should be chosen? As far as I know, you couldn't resolve this by anything with an exception of just removing one of a default values.

免责声明:这是从问题中提取,并张贴在这里代表OP的。