New Errors when moving C++ code to QT Creator
-
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
assert( variableIndex(0,i)<organism_->numParameter());
because
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.
-
@A123 said in New Errors when moving C++ code to QT Creator:
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 calledassert( variableIndex(0,i)<organism_->numParameter());
?
Is it called in the same class where organism_ is declared? -
@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.
-
@A123 said in New Errors when moving C++ code to QT Creator:
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, theassert()
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
NDEBUG
macro, but be careful: This will disable allassert()
s which might cause other errors to go undetected.P.S. The compiler is the one that complained, not Qt Creator.