The following compiles with g++:
// File tagging not working example.
#include <iostream>
using namespace std;
#define AccessorDeclaration(varType, varName) \
varType Get##varName() const; \
void Set##varName(varType newVal);
#define AccessorImplementation(varType, varName, className) \
inline varType className::Get##varName() const { return varName; } \
inline void className::Set##varName(varType newVal) { varName = newVal; };
class MyClass {
public:
MyClass() {MyClassVar = 12;}
AccessorDeclaration(size_t, MyClassVar)
size_t MyClassVar;
};
AccessorImplementation(size_t, MyClassVar, MyClass)
int main(int argc, char ** argv) {
MyClass MyVar;
cout << MyVar.GetMyClassVar() << endl;
MyVar.SetMyClassVar(21);
cout << MyVar.GetMyClassVar();
return 0;
}
Notice the two uses of the preprocessor macros don't have a semicolon, as is not needed.
If you have Symbol coloring on and set to Use strict symbol lookups then:
- The use of AccessorDeclaration in the class is colored as a Public member function. After you place the semicolon after it is correctly colored as a Preprocessor macro.
- The use of AccessorImplementation is colored as a Global function. After you place the semicolon after it is correctly colored as a Preprocessor macro.
- argc and arg v are colored as Symbol not found until AccessorImplementation has the semicolon placed.
- GetMyClassVar and SetMyClassVar are colored as Symbol not found
Again the semicolons are not needed for this to compile. I understand why (4.)
GetMyClassVar and
SetMyClassVar aren't found, but the others seem like bugs. Any way around these?