Следующая строка кода, являющаяся частью файла, выдает ошибку
.\Graph.h:16:3: note: candidate: node::node(int)
node(int n) : element(n){
^~~~
.\Graph.h:16:3: note: candidate expects 1 argument, 0 provided
.\Graph.h:10:8: note: candidate: constexpr node::node(const node&)
struct node{
^~~~
.\Graph.h:10:8: note: candidate expects 1 argument, 0 provided
.\Graph.h:10:8: note: candidate: constexpr node::node(node&&)
.\Graph.h:10:8: note: candidate expects 1 argument, 0 provided
Вышеуказанная ошибка обычно возникает из-за отсутствия конструктора по умолчанию, как я исследовал.
struct node{
int element;
static vector<bool> check;
static vector<int> dist;
static vector<int> f;
static vector<node> leader;
node(int n) : element(n){
if(check.size()<n+1){
check.resize(n+1);
leader.resize(n+1);
}
}
bool operator < (node& n){
if(this->element<n.element)
return 1;
else
return 0;
}
};
Однако конструктор по умолчанию больше нигде не используется.Кроме того, когда я закомментирую static vector<node> leader
и другие связанные с ним операции, программа не выдает никакой ошибки.
Итак, проблема в том, что я объявил контейнер того же типа в том же классе?
EDIT - включено полное сообщение об ошибке
In file included from c:\mingw\lib\gcc\mingw32\6.3.0\include\c++\vector:62:0,
from .\Graph.h:5:
c:\mingw\lib\gcc\mingw32\6.3.0\include\c++\bits\stl_construct.h: In instantiation of 'void std::_Construct(_T1*, _Args&& ...) [with _T1 = node; _Args = {}]':
c:\mingw\lib\gcc\mingw32\6.3.0\include\c++\bits\stl_uninitialized.h:519:18: required from 'static _ForwardIterator std::__uninitialized_default_n_1<_TrivialValueType>::__uninit_default_n(_ForwardIterator, _Size) [with _ForwardIterator = node*; _Size = unsigned int; bool _TrivialValueType = false]'
c:\mingw\lib\gcc\mingw32\6.3.0\include\c++\bits\stl_uninitialized.h:575:20: required from '_ForwardIterator std::__uninitialized_default_n(_ForwardIterator, _Size) [with _ForwardIterator = node*; _Size = unsigned int]'
c:\mingw\lib\gcc\mingw32\6.3.0\include\c++\bits\stl_uninitialized.h:637:44: required from '_ForwardIterator std::__uninitialized_default_n_a(_ForwardIterator, _Size, std::allocator<_Tp>&) [with _ForwardIterator = node*; _Size = unsigned int; _Tp = node]'
c:\mingw\lib\gcc\mingw32\6.3.0\include\c++\bits\vector.tcc:549:35: required from 'void std::vector<_Tp, _Alloc>::_M_default_append(std::vector<_Tp, _Alloc>::size_type) [with _Tp = node; _Alloc = std::allocator<node>; std::vector<_Tp, _Alloc>::size_type = unsigned int]'
c:\mingw\lib\gcc\mingw32\6.3.0\include\c++\bits\stl_vector.h:677:21: required from 'void std::vector<_Tp, _Alloc>::resize(std::vector<_Tp, _Alloc>::size_type) [with _Tp = node; _Alloc = std::allocator<node>; std::vector<_Tp, _Alloc>::size_type = unsigned int]'
.\Graph.h:19:24: required from here
c:\mingw\lib\gcc\mingw32\6.3.0\include\c++\bits\stl_construct.h:75:7: error: no matching function for call to 'node::node()'
{ ::new(static_cast<void*>(__p)) _T1(std::forward<_Args>(__args)...); }
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
.\Graph.h:16:3: note: candidate: node::node(int)
node(int n) : element(n){
^~~~
.\Graph.h:16:3: note: candidate expects 1 argument, 0 provided
.\Graph.h:10:8: note: candidate: constexpr node::node(const node&)
struct node{
^~~~
.\Graph.h:10:8: note: candidate expects 1 argument, 0 provided
.\Graph.h:10:8: note: candidate: constexpr node::node(node&&)
.\Graph.h:10:8: note: candidate expects 1 argument, 0 provided
In file included from c:\mingw\lib\gcc\mingw32\6.3.0\include\c++\vector:62:0,
from .\Graph.h:5:
c:\mingw\lib\gcc\mingw32\6.3.0\include\c++\bits\stl_construct.h: In instantiation of 'void std::_Construct(_T1*, _Args&& ...) [with _T1 = node; _Args = {}]':
c:\mingw\lib\gcc\mingw32\6.3.0\include\c++\bits\stl_uninitialized.h:519:18: required from 'static _ForwardIterator std::__uninitialized_default_n_1<_TrivialValueType>::__uninit_default_n(_ForwardIterator, _Size) [with _ForwardIterator = node*; _Size = unsigned int; bool _TrivialValueType = false]'
c:\mingw\lib\gcc\mingw32\6.3.0\include\c++\bits\stl_uninitialized.h:575:20: required from '_ForwardIterator std::__uninitialized_default_n(_ForwardIterator, _Size) [with _ForwardIterator = node*; _Size = unsigned int]'
c:\mingw\lib\gcc\mingw32\6.3.0\include\c++\bits\stl_uninitialized.h:637:44: required from '_ForwardIterator std::__uninitialized_default_n_a(_ForwardIterator, _Size, std::allocator<_Tp>&) [with _ForwardIterator = node*; _Size = unsigned int; _Tp = node]'
c:\mingw\lib\gcc\mingw32\6.3.0\include\c++\bits\vector.tcc:549:35: required from 'void std::vector<_Tp, _Alloc>::_M_default_append(std::vector<_Tp, _Alloc>::size_type) [with _Tp = node; _Alloc = std::allocator<node>; std::vector<_Tp, _Alloc>::size_type = unsigned int]'
c:\mingw\lib\gcc\mingw32\6.3.0\include\c++\bits\stl_vector.h:677:21: required from 'void std::vector<_Tp, _Alloc>::resize(std::vector<_Tp, _Alloc>::size_type) [with _Tp = node; _Alloc = std::allocator<node>; std::vector<_Tp, _Alloc>::size_type = unsigned int]'
.\Graph.h:19:24: required from here
c:\mingw\lib\gcc\mingw32\6.3.0\include\c++\bits\stl_construct.h:75:7: error: no matching function for call to 'node::node()'
{ ::new(static_cast<void*>(__p)) _T1(std::forward<_Args>(__args)...); }
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
.\Graph.h:16:3: note: candidate: node::node(int)
node(int n) : element(n){
^~~~
.\Graph.h:16:3: note: candidate expects 1 argument, 0 provided
.\Graph.h:10:8: note: candidate: constexpr node::node(const node&)
struct node{
^~~~
.\Graph.h:10:8: note: candidate expects 1 argument, 0 provided
.\Graph.h:10:8: note: candidate: constexpr node::node(node&&)
.\Graph.h:10:8: note: candidate expects 1 argument, 0 provided