Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct
New Errors when moving C++ code to QT Creator
A123 last edited by A123
I'm getting new errors when migrating from using makefiles and clang 4.0.1 on linux mint to using QTcreator as an IDE for convenience. Specifically its complaining that private members are being accessed.... 'is private within this context.' type error
ie this line gives me an error
private: // A pointer to the organism class to be able to get all possible data fields Organism *organism_;
I sorta understand the error but this is the way the code was when I received it, its been used by others for years and it worked perfectly AFAIK with gcc and clang before I started using qtcreator which complained. So I don't want to change it unless I'm sure the code is the problem. So what is wrong? Is it the code or one of the compilers? If you want to see additional code for context I can provide it. The old makefiles appear to include the problematic files so it doesn't look like just a matter of the errors only appearing when a previously unused file was included.
So what is wrong?
Accessing private members is wrong. There is a reason why they are private. You should fix the code.
Also, where exactly is this code called
Is it called in the same class where organism_ is declared?
A123 last edited by
@jsulm its called within a function of Class ParamCopy. ParamCopy is derived from BaseReact which is where
private: Organism *organism_;
@A123 Well, then this code is broken and I'm wondering how it was compiling before. Private elements of a base class can't be accessed from derived classes in C++. This is the case since the beginning of C++. You need to fix the code.
VRonin last edited by
To make it more clear,
its been used by others for years and it worked perfectly AFAIK with gcc and clang before I started using qtcreator which complained.
Here's my guess: Previously, the
assert()macro was disabled. This caused the illegal code to be effectively "commented out", so the compiler didn't detect it. After the migration, the
assert()macro was no longer disabled, so the compiler now sees the bad code and (correctly) complains.
See http://www.cplusplus.com/reference/cassert/assert/. You could make your code work again by defining the
NDEBUGmacro, but be careful: This will disable all
assert()s which might cause other errors to go undetected.
P.S. The compiler is the one that complained, not Qt Creator.