[Error] ‘invalid_argument‘ is not a member of ‘std‘问题解决

本文解析了编程中遇到的invalid_argument异常,探讨了其原因,如头文件缺失、命名空间污染等,并提供了相应的解决步骤,包括正确包含头文件、检查编译器设置以及避免污染std命名空间。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

错误解释:

invalid_argument 是标准库中 std 命名空间下的一个异常类型,用于表示一个方法接收到一个不合法或不正确的参数。当程序抛出 “[Error] ‘invalid_argument’ is not a member of ‘std’” 这个错误时,通常意味着编译器无法在当前的命名空间中找到 std::invalid_argument。

可能的原因:

缺少包含 头文件。

编译器无法正确识别或链接标准库。

代码中可能有命名空间污染,导致 std 被定义为其他内容。

解决方法:

确保包含 头文件。

检查编译器设置,确保启用了标准库的支持。

检查代码中是否有其他命名空间定义了 std,如果有,需要修正它。

如果使用了条件编译或特殊宏定义,确保它们不会覆盖或破坏 std 的定义。

示例:

确保代码中包含了 头文件:

#include <stdexcept>
// 使用 std::invalid_argument 的代码
/usr/local/include/ceres/internal/integer_sequence_algorithm.h:135:59: note: expected a type, got ‘N’ /usr/local/include/ceres/internal/integer_sequence_algorithm.h:146:39: error: ‘integer_sequence’ is not a member ofstd’ 146 | struct ExclusiveScanImpl<T, Sum, std::integer_sequence<T>, SeqOut> { | ^~~~~~~~~~~~~~~~ /usr/local/include/ceres/internal/integer_sequence_algorithm.h:146:39: error: ‘integer_sequence’ is not a member ofstd’ /usr/local/include/ceres/internal/integer_sequence_algorithm.h:146:57: error: wrong number of template arguments (3, should be 4) 146 | struct ExclusiveScanImpl<T, Sum, std::integer_sequence<T>, SeqOut> { | ^ /usr/local/include/ceres/internal/integer_sequence_algorithm.h:130:8: note: provided for ‘template<class T, T Sum, class SeqIn, class SeqOut> struct ceres::internal::ExclusiveScanImpl’ 130 | struct ExclusiveScanImpl; | ^~~~~~~~~~~~~~~~~ /usr/local/include/ceres/internal/integer_sequence_algorithm.h:160:53: error: ‘integer_sequence’ is not a member ofstd’ 160 | typename ExclusiveScanImpl<T, T(0), Seq, std::integer_sequence<T>>::Type; | ^~~~~~~~~~~~~~~~ /usr/local/include/ceres/internal/integer_sequence_algorithm.h:160:53: error: ‘integer_sequence’ is not a member ofstd’ /usr/local/include/ceres/internal/integer_sequence_algorithm.h:160:70: error: template argument 4 is invalid 160 | typename ExclusiveScanImpl<T, T(0), Seq, std::integer_sequence<T>>::Type; | ^ /usr/local/include/ceres/internal/integer_sequence_algorithm.h:160:16: error: expected nested-name-specifier 160 | typename ExclusiveScanImpl<T, T(0), Seq, std::integer_sequence<T>>::Type; | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ In file included from /usr
03-25
In file included from /usr/include/spdlog/spdlog.h:12, from /home/lu/Downloads/rune_ku/g2o-master/g2o/stuff/logger.h:34, from /home/lu/Downloads/rune_ku/g2o-master/g2o/stuff/timeutil.cpp:31: /usr/include/spdlog/common.h:127:111: error: ‘basic_runtime’ is not a member of ‘fmt’ 127 | std::is_convertible<T, fmt::basic_string_view<Char>>::value || std::is_same<remove_cvref_t<T>, fmt::basic_runtime<Char>>::value> | ^~~~~~~~~~~~~ /usr/include/spdlog/common.h:127:125: error: template argument 2 is invalid 127 | std::is_convertible<T, fmt::basic_string_view<Char>>::value || std::is_same<remove_cvref_t<T>, fmt::basic_runtime<Char>>::value> | ^~~~ /usr/include/spdlog/common.h:127:138: error: expected ‘{’ before ‘>’ token 127 | std::is_convertible<T, fmt::basic_string_view<Char>>::value || std::is_same<remove_cvref_t<T>, fmt::basic_runtime<Char>>::value> | ^ In file included from /usr/include/spdlog/spdlog.h:12, from /home/lu/Downloads/rune_ku/g2o-master/g2o/stuff/logger.h:34, from /home/lu/Downloads/rune_ku/g2o-master/g2o/stuff/logger.cpp:27: /usr/include/spdlog/common.h:127:111: error: ‘basic_runtime’ is not a member of ‘fmt’ 127 | std::is_convertible<T, fmt::basic_string_view<Char>>::value || std::is_same<remove_cvref_t<T>, fmt::basic_runtime<Char>>::value> | ^~~~~~~~~~~~~ /usr/include/spdlog/common.h:127:125: error: template argument 2 is invalid 127 | std::is_convertible<T, fmt::basic_string_view<Char>>::value || std::is_same<remove_cvref_t<T>, fmt::basic_runtime<Char>>::value> | ^~~~ /usr/include/spdlog/common.h:127:138: error: expected ‘{’ before ‘>’ token 127 | std::is_convertible<T, fmt::basic_string_view<Char>>::value || std::is_same<remove_cvref_t<T>, fmt::basic_runtime<Char>>::value> | ^ In file included from /usr/include/spdlog/spdlog.h:12, from /home/lu/Downloads/rune_ku/g2o-master/g2o/stuff/logger.h:34, from /home/lu/Downloads/rune_ku/g2o-master/g2o/stuff/property.cpp:32: /usr/include/spdlog/common.h:127:111: error: ‘basic_runtime’ is not a member of ‘fmt’ 127 | std::is_convertible<T, fmt::basic_string_view<Char>>::value || std::is_same<remove_cvref_t<T>, fmt::basic_runtime<Char>>::value> | ^~~~~~~~~~~~~ /usr/include/spdlog/common.h:127:125: error: template argument 2 is invalid 127 | std::is_convertible<T, fmt::basic_string_view<Char>>::value || std::is_same<remove_cvref_t<T>, fmt::basic_runtime<Char>>::value> | ^~~~ /usr/include/spdlog/common.h:127:138: error: expected ‘{’ before ‘>’ token 127 | std::is_convertible<T, fmt::basic_string_view<Char>>::value || std::is_same<remove_cvref_t<T>, fmt::basic_runtime<Char>>::value> | ^ make[2]: *** [g2o/stuff/CMakeFiles/stuff.dir/build.make:79: g2o/stuff/CMakeFiles/stuff.dir/timeutil.cpp.o] Error 1 make[2]: *** Waiting for unfinished jobs.... make[2]: *** [g2o/stuff/CMakeFiles/stuff.dir/build.make:191: g2o/stuff/CMakeFiles/stuff.dir/logger.cpp.o] Error 1 make[2]: *** [g2o/stuff/CMakeFiles/stuff.dir/build.make:149: g2o/stuff/CMakeFiles/stuff.dir/property.cpp.o] Error 1 [ 6%] Linking CXX shared library ../../../../../lib/libg2o_parser.so [ 6%] Built target parser_library [ 6%] Building CXX object g2o/examples/interactive_slam/slam_parser/interface/CMakeFiles/interface_library.dir/parser_interface.cpp.o [ 6%] Building CXX object g2o/examples/interactive_slam/slam_parser/interface/CMakeFiles/interface_library.dir/slam_context_interface.cpp.o [ 7%] Linking CXX shared library ../../../../../lib/libg2o_interface.so [ 7%] Built target interface_library make[1]: *** [CMakeFiles/Makefile2:1422: g2o/stuff/CMakeFiles/stuff.dir/all] Error 2 make: *** [Makefile:156: all] Error 2
06-09
/data/k50048780/cpp_mutator/mutators/BitStream.cpp: In member function ‘BitStream BitStream::slice(size_t, size_t) const’: /data/k50048780/cpp_mutator/mutators/BitStream.cpp:154:46: error: passing ‘const BitStream’ as ‘thisargument discards qualifiers [-fpermissive] 154 | copy_bits(*this, start_bit, 0, bit_length); | ^ In file included from /data/k50048780/cpp_mutator/mutators/BitStream.cpp:5: /data/k50048780/cpp_mutator/mutators/BitStream.h:62:10: note: in call to ‘void BitStream::copy_bits(const BitStream&, size_t, size_t, size_t)’ 62 | void copy_bits(const BitStream& src, size_t src_start, size_t dest_start, size_t bit_count); | ^~~~~~~~~ CMakeFiles/mutator.dir/build.make:446: recipe for target 'CMakeFiles/mutator.dir/mutators/BitStream.cpp.o' failed make[3]: *** [CMakeFiles/mutator.dir/mutators/BitStream.cpp.o] Error 1 make[3]: *** Waiting for unfinished jobs.... /data/k50048780/cpp_mutator/mutators/string/StringLengthEdgeCase.cpp: In constructor ‘StringLengthEdgeCase::StringLengthEdgeCase(std::shared_ptr<StringBase>, std::mt19937)’: /data/k50048780/cpp_mutator/mutators/string/StringLengthEdgeCase.cpp:10:37: error: no matching function for call to ‘IntegerEdgeCases::IntegerEdgeCases(std::shared_ptr<StringBase>&, std::mt19937&)’ 10 | : IntegerEdgeCases(obj, rand) { | ^ In file included from /data/k50048780/cpp_mutator/mutators/string/StringLengthEdgeCase.h:10, from /data/k50048780/cpp_mutator/mutators/string/StringLengthEdgeCase.cpp:5: /data/k50048780/cpp_mutator/mutators/string/../utils.h:146:5: note: candidate: ‘IntegerEdgeCases::IntegerEdgeCases(std::shared_ptr<NumberBase>, std::mt19937&)’ 146 | IntegerEdgeCases(std::shared_ptr<NumberBase> obj, std::mt19937 &rand); | ^~~~~~~~~~~~~~~~ /data/k50048780/cpp_mutator/mutators/string/../utils.h:146:50: note: no known conversion for argument 1 from ‘shared_ptr<StringBase>’ to ‘shared_ptr<NumberBase>’ 146 | IntegerEdgeCases(std::shared_ptr<NumberBase> obj, std::mt19937 &rand); | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~ /data/k50048780/cpp_mutator/mutators/string/../utils.h:144:7: note: candidate: ‘IntegerEdgeCases::IntegerEdgeCases(const IntegerEdgeCases&)’ 144 | class IntegerEdgeCases : public Mutator { | ^~~~~~~~~~~~~~~~ /data/k50048780/cpp_mutator/mutators/string/../utils.h:144:7: note: candidate expects 1 argument, 2 provided /data/k50048780/cpp_mutator/mutators/string/../utils.h:144:7: note: candidate: ‘IntegerEdgeCases::IntegerEdgeCases(IntegerEdgeCases&&)’ /data/k50048780/cpp_mutator/mutators/string/../utils.h:144:7: note: candidate expects 1 argument, 2 provided /data/k50048780/cpp_mutator/mutators/string/StringLengthEdgeCase.cpp: In member function ‘virtual std::pair<long int, long int> StringLengthEdgeCase::get_limits(std::shared_ptr<StringBase>)’: /data/k50048780/cpp_mutator/mutators/string/StringLengthEdgeCase.cpp:24:25: error: request for member ‘has_value’ in ‘((std::__shared_ptr_access<StringBase, __gnu_cxx::_S_atomic, false, false>*)(& obj))->std::__shared_ptr_access<StringBase, __gnu_cxx::_S_atomic, false, false>::operator->()->StringBase::<anonymous>.TypeBase<StringBase>::max_length’, which is of non-class type ‘int64_t’ {aka ‘long int’} 24 | if (obj->max_length.has_value()) { | ^~~~~~~~~ /data/k50048780/cpp_mutator/mutators/string/StringLengthEdgeCase.cpp:25:47: error: request for member ‘value’ in ‘((std::__shared_ptr_access<StringBase, __gnu_cxx::_S_atomic, false, false>*)(& obj))->std::__shared_ptr_access<StringBase, __gnu_cxx::_S_atomic, false, false>::operator->()->StringBase::<anonymous>.TypeBase<StringBase>::max_length’, which is of non-class type ‘int64_t’ {aka ‘long int’} 25 | max_ = std::min(max_, obj->max_length.value()); | ^~~~~ /data/k50048780/cpp_mutator/mutators/string/StringLengthEdgeCase.cpp:29:25: error: request for member ‘has_value’ in ‘((std::__shared_ptr_access<StringBase, __gnu_cxx::_S_atomic, false, false>*)(& obj))->std::__shared_ptr_access<StringBase, __gnu_cxx::_S_atomic, false, false>::operator->()->StringBase::<anonymous>.TypeBase<StringBase>::min_length’, which is of non-class type ‘int64_t’ {aka ‘long int’} 29 | if (obj->min_length.has_value()) { | ^~~~~~~~~ /data/k50048780/cpp_mutator/mutators/string/StringLengthEdgeCase.cpp:30:47: error: request for member ‘value’ in ‘((std::__shared_ptr_access<StringBase, __gnu_cxx::_S_atomic, false, false>*)(& obj))->std::__shared_ptr_access<StringBase, __gnu_cxx::_S_atomic, false, false>::operator->()->StringBase::<anonymous>.TypeBase<StringBase>::min_length’, which is of non-class type ‘int64_t’ {aka ‘long int’} 30 | min_ = std::max(min_, obj->min_length.value()); | ^~~~~ /data/k50048780/cpp_mutator/mutators/string/StringLengthEdgeCase.cpp: At global scope: /data/k50048780/cpp_mutator/mutators/string/StringLengthEdgeCase.cpp:42:6: error: no declaration matches ‘void StringLengthEdgeCase::perform_mutation(std::shared_ptr<StringBase>, int64_t)’ 42 | void StringLengthEdgeCase::perform_mutation(std::shared_ptr<StringBase> obj, int64_t value) { | ^~~~~~~~~~~~~~~~~~~~ In file included from /data/k50048780/cpp_mutator/mutators/string/StringLengthEdgeCase.cpp:5: /data/k50048780/cpp_mutator/mutators/string/StringLengthEdgeCase.h:16:10: note: candidate is: ‘void StringLengthEdgeCase::perform_mutation(std::shared_ptr<String>, size_t)’ 16 | void perform_mutation(std::shared_ptr<String> obj, size_t index); | ^~~~~~~~~~~~~~~~ /data/k50048780/cpp_mutator/mutators/string/StringLengthEdgeCase.h:13:7: note: ‘class StringLengthEdgeCase’ defined here 13 | class StringLengthEdgeCase : public IntegerEdgeCases { | ^~~~~~~~~~~~~~~~~~~~ In file included from /data/k50048780/cpp_mutator/mutators/MutatorFactory.cpp:8: /data/k50048780/cpp_mutator/mutators/number/NumberVariance.h:13:32: error: invalid covariant return type for ‘virtual std::pair<long unsigned int, long unsigned int> NumberVariance::get_limits(std::shared_ptr<NumberBase>)’ 13 | std::pair<size_t ,size_t > get_limits(std::shared_ptr<NumberBase> obj); | ^~~~~~~~~~ In file included from /data/k50048780/cpp_mutator/mutators/string/../../utils/sample_util.h:12, from /data/k50048780/cpp_mutator/mutators/string/StringCaseLower.h:8, from /data/k50048780/cpp_mutator/mutators/MutatorFactory.cpp:6: /data/k50048780/cpp_mutator/mutators/string/../../utils/../mutators/utils.h:70:51: note: overridden function is ‘virtual std::pair<long int, long int> IntegerVariance::get_limits(std::shared_ptr<NumberBase>)’ 70 | virtual std::pair<std::int64_t, std::int64_t> get_limits(std::shared_ptr<NumberBase> obj); | ^~~~~~~~~~
最新发布
06-28
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值