【发布时间】:2014-06-26 06:51:17
【问题描述】:
我有一个 std::set<MyType> 容器,我是通过某个类的 get 函数获得的,即我有这样的东西:
typedef std::set<MyType, compareMyType> MyTypeSet; // this a singleton class class MyClass { ... public: MyTypeSet& getMySet() { return mySet_; } ... private: MyTypeSet mySet_; ... }
然后在其他地方我正在使用这个容器:
MyClass obj;
MyTypeSet& mySet = mtyObj->getMySet();
MyTypeSet::iterator itBeg = mySet.begin();
// Then I'm trying to call f function
f(*itBeg);
其中 f 函数的签名如下:
void f(MyType& param);
我收到这样的编译错误:
note: candidates are: void f(MyType&)
error: no matching function for call to f(const MyType&)
我该如何解决这个问题?
提前致谢。
【问题讨论】:
-
mtyObj 是指向 const 对象的指针吗?
-
不,它不是 const,@Pradhan。