2014-12-05 61 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的。