挥发性的+ C++ 中不允许对象组合?
我正在使用 TI TMS320F28335 的嵌入式编译器,因此我不确定这是一般的 C++ 问题(手头没有运行 C++ 编译器)还是只是我的编译器。将以下代码片段放入我的代码中会出现编译错误:
"build\main.cpp", line 61: error #317: the object has cv-qualifiers that are not
compatible with the member function
object type is: volatile Foo::Bar
当我注释掉下面的 initWontWork()
函数时,该错误消失。错误告诉我什么以及如何解决它,而不必求助于使用在 易失性结构
上运行的 static
函数?
struct Foo
{
struct Bar
{
int x;
void reset() { x = 0; }
static void doReset(volatile Bar& bar) { bar.x = 0; }
} bar;
volatile Bar& getBar() { return bar; }
//void initWontWork() { getBar().reset(); }
void init() { Bar::doReset(getBar()); }
} foo;
I'm using an embedded compiler for the TI TMS320F28335, so I'm not sure if this is a general C++ problem (don't have a C++ compiler running on hand) or just my compiler. Putting the following code snippet in my code gives me a compile error:
"build\main.cpp", line 61: error #317: the object has cv-qualifiers that are not
compatible with the member function
object type is: volatile Foo::Bar
The error goes away when I comment out the initWontWork()
function below. What is the error telling me and how can I get around it without having to resort to using static
functions that operate on a volatile struct
?
struct Foo
{
struct Bar
{
int x;
void reset() { x = 0; }
static void doReset(volatile Bar& bar) { bar.x = 0; }
} bar;
volatile Bar& getBar() { return bar; }
//void initWontWork() { getBar().reset(); }
void init() { Bar::doReset(getBar()); }
} foo;
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
同样,你不能这样做:
你不能这样做:
你必须对函数进行简历限定:
所以对你来说:
In the same way you cannot do this:
You cannot do this:
You must cv-qualify the functions:
So for you: