相关疑难解决方法(0)

为什么g ++会说'不匹配'运算符=',当有明显的情况时,Visual Studio可以看到有?

我正在编写一个接口库,允许在类型的对象中访问表中的变量(理论上无限深度)regula::State.我通过operator[]在类中重载来完成此操作,然后返回该类的另一个类,并operator[]根据需要再次调用.例如:

regula::State t;
t["math"]["pi"] = 3.14159;
Run Code Online (Sandbox Code Playgroud)

以上应该将值放在表中的3.14159变量pimath.基本上,它通过t返回一个代理对象来执行此操作,该代理对象math返回另一个代表pi我们实际保存变量的代理对象.这个内部与问题无关,但这里是函数头.

LObject LObject::operator[] (const std::string name);
Run Code Online (Sandbox Code Playgroud)

基本上,在上面的例子中,程序应该使用字符串调用t's 并返回另一个对象,然后使用返回最终对象的字符串调用该对象,然后使用该字符串将值赋给该对象.operator[]"math"operator[]"pi"operator=

template <typename T>
T LObject::operator= (const T& value);
Run Code Online (Sandbox Code Playgroud)

T返回的只是一个副本value通过.

现在,我的代码在Visual C++ 2008中产生NO错误并且工作正常.但是当我尝试在Linux上编译它时g++,我收到以下错误:

../../test/regula-test.cpp:100: error: no match for ‘operator=’ in 
‘L.regula::State::operator[](std::basic_string<char, std::char_traits<char>, 
std::allocator<char> >(((const char*)"Numbers"), ((const std::allocator<char>&)((const 
std::allocator<char>*)(& std::allocator<char>()))))) = Numbers’
../../include/regula.hpp:855: note: candidates are: regula::LObject& …
Run Code Online (Sandbox Code Playgroud)

c++ compiler-errors g++ operators

6
推荐指数
1
解决办法
2万
查看次数

标签 统计

c++ ×1

compiler-errors ×1

g++ ×1

operators ×1