【发布时间】:2020-02-24 19:48:45
【问题描述】:
我想跟踪我传递给 API 函数的全局变量。我发现可以使用一个类来做到这一点:
template <class T>
class MonitoredVariable
{
public:
MonitoredVariable() {}
MonitoredVariable(const T& value) : m_value(value) {}
//T operator T() const { return m_value; }
const MonitoredVariable& operator = (const T& value)
{
PlugIn::gResultOut << "value changed " << std::endl;
m_value = value;
return *this;
}
private:
T m_value;
};
API函数将变量作为
bool APIFunction(double time, bool *is_done, double *fraction_done);
以下给我一个错误:
ImagePtr Im;
bool is_done;
MonitoredVariable<double*> fraction_done;
bool frameready = Im->APIFunction(2.1, is_done, fraction_done);
ERROR:
error C2664: cannot convert argument 3 from 'MonitoredVariable<double *>' to 'double *'
我需要在这里改变什么? 谢谢!
【问题讨论】:
-
在函数调用中使用
*is_done是不是拼写错误?如果没有,你真的应该从good textbook 那里学习该语言的基础知识。 -
是的,这是一个错字。 fraction_done 是这里的问题....
-
请在你的帖子中修正这个问题,这样其他人就不会被它分心/困惑。
标签: api c++11 pointers pass-by-reference