Unstable + combination of objects forbidden in C ++?

I use the built-in compiler for TI TMS320F28335, so I'm not sure if this is a common problem in C ++ (I don't have a C ++ compiler) or just my compiler. Entering the code in my code gives me a compilation 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 is skipped when I comment on the initWontWork() function below. What error tells me and how can I get around this without having to use static functions that work with 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; 
+4
source share
1 answer

Similarly, you cannot do this:

 struct foo { void bar(); }; const foo f; f.bar(); // error, non-const function with const object 

You cannot do this:

 struct baz { void qax(); }; volatile baz g; g.qax(); // error, non-volatile function with volatile object 

You must cv-qualify functions:

 struct foo { void bar() const; }; struct baz { void qax() volatile; }; const foo f; f.bar(); // okay volatile baz g; g.qax(); // okay 

So for you:

 void reset() volatile { x = 0; } 
+11
source

All Articles