【发布时间】:2021-01-06 06:47:06
【问题描述】:
你好,我需要使用两个类,比如 blow
c1 类文件
#include<iostream>
#include<variant>
class c1{
private:
...
std::variant<c2,int,double,std::string> a;
public:
...
c2 getA(){
return a;
}
};
在 c2 类文件中
#include<iostream>
#include<vector>
class c2{
private:
...
std::vector<c1> b;
public:
...
c1 getB(){
return b;
}
};
我觉得我的代码不太好
任何人都可以帮助解决或做到这一点
我在这两个标题中使用了这样的方法
class c1;
class c2{...};
但我仍然无法使用 c1 类创建变量
我只能创建指针,但无法在 std::variant
中正确使用它们我尝试将它们包含在内,但编译器出错
我能做些什么来解决这个问题?
请帮忙
编辑:
我尝试将它们包含在内,但编译器出错
就是这个错误
In file included from C:/PROGRA~1/MINGW-~1/X86_64~1.0-P/mingw64/lib/gcc/x86_64-w64-mingw32/8.1.0/include/c++/bits/move.h:55,
from C:/PROGRA~1/MINGW-~1/X86_64~1.0-P/mingw64/lib/gcc/x86_64-w64-mingw32/8.1.0/include/c++/bits/nested_exception.h:40,
from C:/PROGRA~1/MINGW-~1/X86_64~1.0-P/mingw64/lib/gcc/x86_64-w64-mingw32/8.1.0/include/c++/exception:144,
from C:/PROGRA~1/MINGW-~1/X86_64~1.0-P/mingw64/lib/gcc/x86_64-w64-mingw32/8.1.0/include/c++/ios:39,
from C:/PROGRA~1/MINGW-~1/X86_64~1.0-P/mingw64/lib/gcc/x86_64-w64-mingw32/8.1.0/include/c++/ostream:38,
from C:/PROGRA~1/MINGW-~1/X86_64~1.0-P/mingw64/lib/gcc/x86_64-w64-mingw32/8.1.0/include/c++/iostream:39,
from C:\Users\M\CLionProjects\MyJson\my_json\JSONObject.h:9,
from C:\Users\M\CLionProjects\MyJson\my_json\JSONObject.cpp:5:
C:/PROGRA~1/MINGW-~1/X86_64~1.0-P/mingw64/lib/gcc/x86_64-w64-mingw32/8.1.0/include/c++/type_traits: In instantiation of 'struct std::is_trivially_destructible<JSONObject>':
C:/PROGRA~1/MINGW-~1/X86_64~1.0-P/mingw64/lib/gcc/x86_64-w64-mingw32/8.1.0/include/c++/type_traits:2846:25: required from 'constexpr const bool std::is_trivially_destructible_v<JSONObject>'
C:/PROGRA~1/MINGW-~1/X86_64~1.0-P/mingw64/lib/gcc/x86_64-w64-mingw32/8.1.0/include/c++/variant:313:5: required from 'constexpr const bool std::__detail::__variant::_Traits<int, double, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, JSONObject>::_S_trivial_dtor'
C:/PROGRA~1/MINGW-~1/X86_64~1.0-P/mingw64/lib/gcc/x86_64-w64-mingw32/8.1.0/include/c++/variant:321:20: required from 'constexpr const bool std::__detail::__variant::_Traits<int, double, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, JSONObject>::_S_trivial_move_assign'
C:/PROGRA~1/MINGW-~1/X86_64~1.0-P/mingw64/lib/gcc/x86_64-w64-mingw32/8.1.0/include/c++/variant:646:16: required by substitution of 'template<class ... _Types> using _Move_assign_alias = std::__detail::__variant::_Move_assign_base<std::__detail::__variant::_Traits<_Types>::_S_trivial_move_assign, _Types ...> [with _Types = {int, double, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, JSONObject}]'
C:/PROGRA~1/MINGW-~1/X86_64~1.0-P/mingw64/lib/gcc/x86_64-w64-mingw32/8.1.0/include/c++/variant:649:12: required from 'struct std::__detail::__variant::_Variant_base<int, double, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, JSONObject>'
C:/PROGRA~1/MINGW-~1/X86_64~1.0-P/mingw64/lib/gcc/x86_64-w64-mingw32/8.1.0/include/c++/variant:1038:11: required from 'class std::variant<int, double, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, JSONObject>'
C:\Users\M\CLionProjects\MyJson\my_json\JSONType.h:22:62: required from here
C:/PROGRA~1/MINGW-~1/X86_64~1.0-P/mingw64/lib/gcc/x86_64-w64-mingw32/8.1.0/include/c++/type_traits:1282:12: error: invalid use of incomplete type 'class JSONObject'
struct is_trivially_destructible
^~~~~~~~~~~~~~~~~~~~~~~~~
In file included from C:\Users\M\CLionProjects\MyJson\my_json\JSONObject.h:14,
from C:\Users\M\CLionProjects\MyJson\my_json\JSONObject.cpp:5:
C:\Users\M\CLionProjects\MyJson\my_json\JSONType.h:14:7: note: forward declaration of 'class JSONObject'
class JSONObject;
^~~~~~~~~~
In file included from C:/PROGRA~1/MINGW-~1/X86_64~1.0-P/mingw64/lib/gcc/x86_64-w64-mingw32/8.1.0/include/c++/bits/move.h:55,
from C:/PROGRA~1/MINGW-~1/X86_64~1.0-P/mingw64/lib/gcc/x86_64-w64-mingw32/8.1.0/include/c++/bits/nested_exception.h:40,
from C:/PROGRA~1/MINGW-~1/X86_64~1.0-P/mingw64/lib/gcc/x86_64-w64-mingw32/8.1.0/include/c++/exception:144,
from C:/PROGRA~1/MINGW-~1/X86_64~1.0-P/mingw64/lib/gcc/x86_64-w64-mingw32/8.1.0/include/c++/ios:39,
from C:/PROGRA~1/MINGW-~1/X86_64~1.0-P/mingw64/lib/gcc/x86_64-w64-mingw32/8.1.0/include/c++/ostream:38,
from C:/PROGRA~1/MINGW-~1/X86_64~1.0-P/mingw64/lib/gcc/x86_64-w64-mingw32/8.1.0/include/c++/iostream:39,
from C:\Users\M\CLionProjects\MyJson\my_json\JSONObject.h:9,
from C:\Users\M\CLionProjects\MyJson\my_json\JSONObject.cpp:5:
C:/PROGRA~1/MINGW-~1/X86_64~1.0-P/mingw64/lib/gcc/x86_64-w64-mingw32/8.1.0/include/c++/type_traits: In instantiation of 'constexpr const bool std::is_trivially_destructible_v<JSONObject>':
C:/PROGRA~1/MINGW-~1/X86_64~1.0-P/mingw64/lib/gcc/x86_64-w64-mingw32/8.1.0/include/c++/variant:313:5: required from 'constexpr const bool std::__detail::__variant::_Traits<int, double, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, JSONObject>::_S_trivial_dtor'
C:/PROGRA~1/MINGW-~1/X86_64~1.0-P/mingw64/lib/gcc/x86_64-w64-mingw32/8.1.0/include/c++/variant:321:20: required from 'constexpr const bool std::__detail::__variant::_Traits<int, double, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, JSONObject>::_S_trivial_move_assign'
C:/PROGRA~1/MINGW-~1/X86_64~1.0-P/mingw64/lib/gcc/x86_64-w64-mingw32/8.1.0/include/c++/variant:646:16: required by substitution of 'template<class ... _Types> using _Move_assign_alias = std::__detail::__variant::_Move_assign_base<std::__detail::__variant::_Traits<_Types>::_S_trivial_move_assign, _Types ...> [with _Types = {int, double, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, JSONObject}]'
C:/PROGRA~1/MINGW-~1/X86_64~1.0-P/mingw64/lib/gcc/x86_64-w64-mingw32/8.1.0/include/c++/variant:649:12: required from 'struct std::__detail::__variant::_Variant_base<int, double, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, JSONObject>'
C:/PROGRA~1/MINGW-~1/X86_64~1.0-P/mingw64/lib/gcc/x86_64-w64-mingw32/8.1.0/include/c++/variant:1038:11: required from 'class std::variant<int, double, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, JSONObject>'
C:\Users\M\CLionProjects\MyJson\my_json\JSONType.h:22:62: required from here
C:/PROGRA~1/MINGW-~1/X86_64~1.0-P/mingw64/lib/gcc/x86_64-w64-mingw32/8.1.0/include/c++/type_traits:2846:25: error: 'value' is not a member of 'std::is_trivially_destructible<JSONObject>'
inline constexpr bool is_trivially_destructible_v =
^~~~~~~~~~~~~~~~~~~~~~~~~~~
C:/PROGRA~1/MINGW-~1/X86_64~1.0-P/mingw64/lib/gcc/x86_64-w64-mingw32/8.1.0/include/c++/type_traits: In instantiation of 'struct std::__is_trivially_move_constructible_impl<JSONObject, true>':
C:/PROGRA~1/MINGW-~1/X86_64~1.0-P/mingw64/lib/gcc/x86_64-w64-mingw32/8.1.0/include/c++/type_traits:1228:12: required from 'struct std::is_trivially_move_constructible<JSONObject>'
C:/PROGRA~1/MINGW-~1/X86_64~1.0-P/mingw64/lib/gcc/x86_64-w64-mingw32/8.1.0/include/c++/type_traits:2834:25: required from 'constexpr const bool std::is_trivially_move_constructible_v<JSONObject>'
C:/PROGRA~1/MINGW-~1/X86_64~1.0-P/mingw64/lib/gcc/x86_64-w64-mingw32/8.1.0/include/c++/variant:317:5: required from 'constexpr const bool std::__detail::__variant::_Traits<int, double, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, JSONObject>::_S_trivial_move_ctor'
C:/PROGRA~1/MINGW-~1/X86_64~1.0-P/mingw64/lib/gcc/x86_64-w64-mingw32/8.1.0/include/c++/variant:523:70: required by substitution of 'template<class ... _Types> using _Move_ctor_alias = std::__detail::__variant::_Move_ctor_base<std::__detail::__variant::_Traits<_Types>::_S_trivial_move_ctor, _Types ...> [with _Types = {int, double, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, JSONObject}]'
C:/PROGRA~1/MINGW-~1/X86_64~1.0-P/mingw64/lib/gcc/x86_64-w64-mingw32/8.1.0/include/c++/variant:526:12: required from 'struct std::__detail::__variant::_Copy_assign_base<false, int, double, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, JSONObject>'
C:/PROGRA~1/MINGW-~1/X86_64~1.0-P/mingw64/lib/gcc/x86_64-w64-mingw32/8.1.0/include/c++/variant:580:12: required from 'struct std::__detail::__variant::_Move_assign_base<false, int, double, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, JSONObject>'
C:/PROGRA~1/MINGW-~1/X86_64~1.0-P/mingw64/lib/gcc/x86_64-w64-mingw32/8.1.0/include/c++/variant:649:12: required from 'struct std::__detail::__variant::_Variant_base<int, double, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, JSONObject>'
C:/PROGRA~1/MINGW-~1/X86_64~1.0-P/mingw64/lib/gcc/x86_64-w64-mingw32/8.1.0/include/c++/variant:1038:11: required from 'class std::variant<int, double, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, JSONObject>'
C:\Users\M\CLionProjects\MyJson\my_json\JSONType.h:22:62: required from here
C:/PROGRA~1/MINGW-~1/X86_64~1.0-P/mingw64/lib/gcc/x86_64-w64-mingw32/8.1.0/include/c++/type_traits:1221:12: error: invalid use of incomplete type 'class JSONObject'
struct __is_trivially_move_constructible_impl<_Tp, true>
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
In file included from C:\Users\M\CLionProjects\MyJson\my_json\JSONObject.h:14,
from C:\Users\M\CLionProjects\MyJson\my_json\JSONObject.cpp:5:
C:\Users\M\CLionProjects\MyJson\my_json\JSONType.h:14:7: note: forward declaration of 'class JSONObject'
class JSONObject;
^~~~~~~~~~
In file included from C:/PROGRA~1/MINGW-~1/X86_64~1.0-P/mingw64/lib/gcc/x86_64-w64-mingw32/8.1.0/include/c++/bits/move.h:55,
from C:/PROGRA~1/MINGW-~1/X86_64~1.0-P/mingw64/lib/gcc/x86_64-w64-mingw32/8.1.0/include/c++/bits/nested_exception.h:40,
from C:/PROGRA~1/MINGW-~1/X86_64~1.0-P/mingw64/lib/gcc/x86_64-w64-mingw32/8.1.0/include/c++/exception:144,
from C:/PROGRA~1/MINGW-~1/X86_64~1.0-P/mingw64/lib/gcc/x86_64-w64-mingw32/8.1.0/include/c++/ios:39,
from C:/PROGRA~1/MINGW-~1/X86_64~1.0-P/mingw64/lib/gcc/x86_64-w64-mingw32/8.1.0/include/c++/ostream:38,
from C:/PROGRA~1/MINGW-~1/X86_64~1.0-P/mingw64/lib/gcc/x86_64-w64-mingw32/8.1.0/include/c++/iostream:39,
from C:\Users\M\CLionProjects\MyJson\my_json\JSONObject.h:9,
from C:\Users\M\CLionProjects\MyJson\my_json\JSONObject.cpp:5:
C:/PROGRA~1/MINGW-~1/X86_64~1.0-P/mingw64/lib/gcc/x86_64-w64-mingw32/8.1.0/include/c++/type_traits: In instantiation of 'constexpr const bool std::is_trivially_move_constructible_v<JSONObject>':
C:/PROGRA~1/MINGW-~1/X86_64~1.0-P/mingw64/lib/gcc/x86_64-w64-mingw32/8.1.0/include/c++/variant:317:5: required from 'constexpr const bool std::__detail::__variant::_Traits<int, double, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, JSONObject>::_S_trivial_move_ctor'
C:/PROGRA~1/MINGW-~1/X86_64~1.0-P/mingw64/lib/gcc/x86_64-w64-mingw32/8.1.0/include/c++/variant:523:70: required by substitution of 'template<class ... _Types> using _Move_ctor_alias = std::__detail::__variant::_Move_ctor_base<std::__detail::__variant::_Traits<_Types>::_S_trivial_move_ctor, _Types ...> [with _Types = {int, double, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, JSONObject}]'
C:/PROGRA~1/MINGW-~1/X86_64~1.0-P/mingw64/lib/gcc/x86_64-w64-mingw32/8.1.0/include/c++/variant:526:12: required from 'struct std::__detail::__variant::_Copy_assign_base<false, int, double, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, JSONObject>'
C:/PROGRA~1/MINGW-~1/X86_64~1.0-P/mingw64/lib/gcc/x86_64-w64-mingw32/8.1.0/include/c++/variant:580:12: required from 'struct std::__detail::__variant::_Move_assign_base<false, int, double, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, JSONObject>'
C:/PROGRA~1/MINGW-~1/X86_64~1.0-P/mingw64/lib/gcc/x86_64-w64-mingw32/8.1.0/include/c++/variant:649:12: required from 'struct std::__detail::__variant::_Variant_base<int, double, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, JSONObject>'
C:/PROGRA~1/MINGW-~1/X86_64~1.0-P/mingw64/lib/gcc/x86_64-w64-mingw32/8.1.0/include/c++/variant:1038:11: required from 'class std::variant<int, double, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, JSONObject>'
C:\Users\M\CLionProjects\MyJson\my_json\JSONType.h:22:62: required from here
C:/PROGRA~1/MINGW-~1/X86_64~1.0-P/mingw64/lib/gcc/x86_64-w64-mingw32/8.1.0/include/c++/type_traits:2834:25: error: 'value' is not a member of 'std::is_trivially_move_constructible<JSONObject>'
inline constexpr bool is_trivially_move_constructible_v =
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
C:/PROGRA~1/MINGW-~1/X86_64~1.0-P/mingw64/lib/gcc/x86_64-w64-mingw32/8.1.0/include/c++/type_traits: In instantiation of 'struct std::__is_trivially_copy_constructible_impl<JSONObject, true>':
C:/PROGRA~1/MINGW-~1/X86_64~1.0-P/mingw64/lib/gcc/x86_64-w64-mingw32/8.1.0/include/c++/type_traits:1207:12: required from 'struct std::is_trivially_copy_constructible<JSONObject>'
C:/PROGRA~1/MINGW-~1/X86_64~1.0-P/mingw64/lib/gcc/x86_64-w64-mingw32/8.1.0/include/c++/type_traits:2831:25: required from 'constexpr const bool std::is_trivially_copy_constructible_v<JSONObject>'
C:/PROGRA~1/MINGW-~1/X86_64~1.0-P/mingw64/lib/gcc/x86_64-w64-mingw32/8.1.0/include/c++/variant:315:5: required from 'constexpr const bool std::__detail::__variant::_Traits<int, double, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, JSONObject>::_S_trivial_copy_ctor'
C:/PROGRA~1/MINGW-~1/X86_64~1.0-P/mingw64/lib/gcc/x86_64-w64-mingw32/8.1.0/include/c++/variant:489:70: required by substitution of 'template<class ... _Types> using _Copy_ctor_alias = std::__detail::__variant::_Copy_ctor_base<std::__detail::__variant::_Traits<_Types>::_S_trivial_copy_ctor, _Types ...> [with _Types = {int, double, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, JSONObject}]'
C:/PROGRA~1/MINGW-~1/X86_64~1.0-P/mingw64/lib/gcc/x86_64-w64-mingw32/8.1.0/include/c++/variant:492:12: required from 'struct std::__detail::__variant::_Move_ctor_base<false, int, double, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, JSONObject>'
C:/PROGRA~1/MINGW-~1/X86_64~1.0-P/mingw64/lib/gcc/x86_64-w64-mingw32/8.1.0/include/c++/variant:526:12: required from 'struct std::__detail::__variant::_Copy_assign_base<false, int, double, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, JSONObject>'
C:/PROGRA~1/MINGW-~1/X86_64~1.0-P/mingw64/lib/gcc/x86_64-w64-mingw32/8.1.0/include/c++/variant:580:12: required from 'struct std::__detail::__variant::_Move_assign_base<false, int, double, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, JSONObject>'
C:/PROGRA~1/MINGW-~1/X86_64~1.0-P/mingw64/lib/gcc/x86_64-w64-mingw32/8.1.0/include/c++/variant:649:12: required from 'struct std::__detail::__variant::_Variant_base<int, double, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, JSONObject>'
C:/PROGRA~1/MINGW-~1/X86_64~1.0-P/mingw64/lib/gcc/x86_64-w64-mingw32/8.1.0/include/c++/variant:1038:11: required from 'class std::variant<int, double, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, JSONObject>'
C:\Users\M\CLionProjects\MyJson\my_json\JSONType.h:22:62: required from here
C:/PROGRA~1/MINGW-~1/X86_64~1.0-P/mingw64/lib/gcc/x86_64-w64-mingw32/8.1.0/include/c++/type_traits:1200:12: error: invalid use of incomplete type 'class JSONObject'
struct __is_trivially_copy_constructible_impl<_Tp, true>
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
In file included from C:\Users\M\CLionProjects\MyJson\my_json\JSONObject.h:14,
from C:\Users\M\CLionProjects\MyJson\my_json\JSONObject.cpp:5:
C:\Users\M\CLionProjects\MyJson\my_json\JSONType.h:14:7: note: forward declaration of 'class JSONObject'
class JSONObject;
^~~~~~~~~~
In file included from C:/PROGRA~1/MINGW-~1/X86_64~1.0-P/mingw64/lib/gcc/x86_64-w64-mingw32/8.1.0/include/c++/bits/move.h:55,
from C:/PROGRA~1/MINGW-~1/X86_64~1.0-P/mingw64/lib/gcc/x86_64-w64-mingw32/8.1.0/include/c++/bits/nested_exception.h:40,
from C:/PROGRA~1/MINGW-~1/X86_64~1.0-P/mingw64/lib/gcc/x86_64-w64-mingw32/8.1.0/include/c++/exception:144,
from C:/PROGRA~1/MINGW-~1/X86_64~1.0-P/mingw64/lib/gcc/x86_64-w64-mingw32/8.1.0/include/c++/ios:39,
from C:/PROGRA~1/MINGW-~1/X86_64~1.0-P/mingw64/lib/gcc/x86_64-w64-mingw32/8.1.0/include/c++/ostream:38,
from C:/PROGRA~1/MINGW-~1/X86_64~1.0-P/mingw64/lib/gcc/x86_64-w64-mingw32/8.1.0/include/c++/iostream:39,
from C:\Users\M\CLionProjects\MyJson\my_json\JSONObject.h:9,
from C:\Users\M\CLionProjects\MyJson\my_json\JSONObject.cpp:5:
C:/PROGRA~1/MINGW-~1/X86_64~1.0-P/mingw64/lib/gcc/x86_64-w64-mingw32/8.1.0/include/c++/type_traits: In instantiation of 'constexpr const bool std::is_trivially_copy_constructible_v<JSONObject>':
C:/PROGRA~1/MINGW-~1/X86_64~1.0-P/mingw64/lib/gcc/x86_64-w64-mingw32/8.1.0/include/c++/variant:315:5: required from 'constexpr const bool std::__detail::__variant::_Traits<int, double, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, JSONObject>::_S_trivial_copy_ctor'
C:/PROGRA~1/MINGW-~1/X86_64~1.0-P/mingw64/lib/gcc/x86_64-w64-mingw32/8.1.0/include/c++/variant:489:70: required by substitution of 'template<class ... _Types> using _Copy_ctor_alias = std::__detail::__variant::_Copy_ctor_base<std::__detail::__variant::_Traits<_Types>::_S_trivial_copy_ctor, _Types ...> [with _Types = {int, double, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, JSONObject}]'
C:/PROGRA~1/MINGW-~1/X86_64~1.0-P/mingw64/lib/gcc/x86_64-w64-mingw32/8.1.0/include/c++/variant:492:12: required from 'struct std::__detail::__variant::_Move_ctor_base<false, int, double, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, JSONObject>'
C:/PROGRA~1/MINGW-~1/X86_64~1.0-P/mingw64/lib/gcc/x86_64-w64-mingw32/8.1.0/include/c++/variant:526:12: required from 'struct std::__detail::__variant::_Copy_assign_base<false, int, double, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, JSONObject>'
C:/PROGRA~1/MINGW-~1/X86_64~1.0-P/mingw64/lib/gcc/x86_64-w64-mingw32/8.1.0/include/c++/variant:580:12: required from 'struct std::__detail::__variant::_Move_assign_base<false, int, double, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, JSONObject>'
C:/PROGRA~1/MINGW-~1/X86_64~1.0-P/mingw64/lib/gcc/x86_64-w64-mingw32/8.1.0/include/c++/variant:649:12: required from 'struct std::__detail::__variant::_Variant_base<int, double, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, JSONObject>'
C:/PROGRA~1/MINGW-~1/X86_64~1.0-P/mingw64/lib/gcc/x86_64-w64-mingw32/8.1.0/include/c++/variant:1038:11: required from 'class std::variant<int, double, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, JSONObject>'
C:\Users\M\CLionProjects\MyJson\my_json\JSONType.h:22:62: required from here
C:/PROGRA~1/MINGW-~1/X86_64~1.0-P/mingw64/lib/gcc/x86_64-w64-mingw32/8.1.0/include/c++/type_traits:2831:25: error: 'value' is not a member of 'std::is_trivially_copy_constructible<JSONObject>'
inline constexpr bool is_trivially_copy_constructible_v =
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
C:/PROGRA~1/MINGW-~1/X86_64~1.0-P/mingw64/lib/gcc/x86_64-w64-mingw32/8.1.0/include/c++/type_traits: In instantiation of 'struct std::is_literal_type<JSONObject>':
C:/PROGRA~1/MINGW-~1/X86_64~1.0-P/mingw64/lib/gcc/x86_64-w64-mingw32/8.1.0/include/c++/type_traits:2791:25: required from 'constexpr const bool std::is_literal_type_v<JSONObject>'
C:/PROGRA~1/MINGW-~1/X86_64~1.0-P/mingw64/lib/gcc/x86_64-w64-mingw32/8.1.0/include/c++/variant:356:33: recursively required from 'union std::__detail::__variant::_Variadic_union<double, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, JSONObject>'
C:/PROGRA~1/MINGW-~1/X86_64~1.0-P/mingw64/lib/gcc/x86_64-w64-mingw32/8.1.0/include/c++/variant:356:33: required from 'union std::__detail::__variant::_Variadic_union<int, double, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, JSONObject>'
C:/PROGRA~1/MINGW-~1/X86_64~1.0-P/mingw64/lib/gcc/x86_64-w64-mingw32/8.1.0/include/c++/variant:413:34: required from 'struct std::__detail::__variant::_Variant_storage<false, int, double, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, JSONObject>'
C:/PROGRA~1/MINGW-~1/X86_64~1.0-P/mingw64/lib/gcc/x86_64-w64-mingw32/8.1.0/include/c++/variant:458:12: required from 'struct std::__detail::__variant::_Copy_ctor_base<false, int, double, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, JSONObject>'
C:/PROGRA~1/MINGW-~1/X86_64~1.0-P/mingw64/lib/gcc/x86_64-w64-mingw32/8.1.0/include/c++/variant:492:12: required from 'struct std::__detail::__variant::_Move_ctor_base<false, int, double, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, JSONObject>'
C:/PROGRA~1/MINGW-~1/X86_64~1.0-P/mingw64/lib/gcc/x86_64-w64-mingw32/8.1.0/include/c++/variant:526:12: required from 'struct std::__detail::__variant::_Copy_assign_base<false, int, double, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, JSONObject>'
C:/PROGRA~1/MINGW-~1/X86_64~1.0-P/mingw64/lib/gcc/x86_64-w64-mingw32/8.1.0/include/c++/variant:580:12: required from 'struct std::__detail::__variant::_Move_assign_base<false, int, double, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, JSONObject>'
C:/PROGRA~1/MINGW-~1/X86_64~1.0-P/mingw64/lib/gcc/x86_64-w64-mingw32/8.1.0/include/c++/variant:649:12: required from 'struct std::__detail::__variant::_Variant_base<int, double, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, JSONObject>'
C:/PROGRA~1/MINGW-~1/X86_64~1.0-P/mingw64/lib/gcc/x86_64-w64-mingw32/8.1.0/include/c++/variant:1038:11: required from 'class std::variant<int, double, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, JSONObject>'
C:\Users\M\CLionProjects\MyJson\my_json\JSONType.h:22:62: required from here
C:/PROGRA~1/MINGW-~1/X86_64~1.0-P/mingw64/lib/gcc/x86_64-w64-mingw32/8.1.0/include/c++/type_traits:698:12: error: invalid use of incomplete type 'class JSONObject'
struct is_literal_type
^~~~~~~~~~~~~~~
In file included from C:\Users\M\CLionProjects\MyJson\my_json\JSONObject.h:14,
from C:\Users\M\CLionProjects\MyJson\my_json\JSONObject.cpp:5:
C:\Users\M\CLionProjects\MyJson\my_json\JSONType.h:14:7: note: forward declaration of 'class JSONObject'
class JSONObject;
^~~~~~~~~~
In file included from C:/PROGRA~1/MINGW-~1/X86_64~1.0-P/mingw64/lib/gcc/x86_64-w64-mingw32/8.1.0/include/c++/bits/move.h:55,
from C:/PROGRA~1/MINGW-~1/X86_64~1.0-P/mingw64/lib/gcc/x86_64-w64-mingw32/8.1.0/include/c++/bits/nested_exception.h:40,
from C:/PROGRA~1/MINGW-~1/X86_64~1.0-P/mingw64/lib/gcc/x86_64-w64-mingw32/8.1.0/include/c++/exception:144,
from C:/PROGRA~1/MINGW-~1/X86_64~1.0-P/mingw64/lib/gcc/x86_64-w64-mingw32/8.1.0/include/c++/ios:39,
from C:/PROGRA~1/MINGW-~1/X86_64~1.0-P/mingw64/lib/gcc/x86_64-w64-mingw32/8.1.0/include/c++/ostream:38,
from C:/PROGRA~1/MINGW-~1/X86_64~1.0-P/mingw64/lib/gcc/x86_64-w64-mingw32/8.1.0/include/c++/iostream:39,
from C:\Users\M\CLionProjects\MyJson\my_json\JSONObject.h:9,
from C:\Users\M\CLionProjects\MyJson\my_json\JSONObject.cpp:5:
C:/PROGRA~1/MINGW-~1/X86_64~1.0-P/mingw64/lib/gcc/x86_64-w64-mingw32/8.1.0/include/c++/type_traits: In instantiation of 'constexpr const bool std::is_literal_type_v<JSONObject>':
C:/PROGRA~1/MINGW-~1/X86_64~1.0-P/mingw64/lib/gcc/x86_64-w64-mingw32/8.1.0/include/c++/variant:356:33: recursively required from 'union std::__detail::__variant::_Variadic_union<double, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, JSONObject>'
...
mingw32-make.exe[3]: *** [CMakeFiles\MyJson.dir\build.make:75: CMakeFiles/MyJson.dir/my_json/JSONObject.cpp.obj] Error 1
mingw32-make.exe[3]: *** Waiting for unfinished jobs....
mingw32-make.exe[3]: *** [CMakeFiles\MyJson.dir\build.make:88: CMakeFiles/MyJson.dir/my_json/JSONType.cpp.obj] Error 1
mingw32-make.exe[2]: *** [CMakeFiles\Makefile2:75: CMakeFiles/MyJson.dir/all] Error 2
mingw32-make.exe[1]: *** [CMakeFiles\Makefile2:82: CMakeFiles/MyJson.dir/rule] Error 2
mingw32-make.exe: *** [Makefile:117: MyJson] Error 2
【问题讨论】:
-
包含必要的头文件时收到的错误消息是什么?请发布错误。
-
你听说过头后卫吗?