According to the error codes, the compiler (MSVC 2019) is not detecting properly declared classes.
In the following code, the compiler halts at the first mention of UACvLogin in the UACcDefault class definition.
[\src\UAC\controllers\UACcDefault.h][1]:
#ifndef MANAGER_UACCDEFAULT_H
#define MANAGER_UACCDEFAULT_H
#include "src/includes.h"
#include "../views/UACvLogin.h"
#include "../models/UACmUsers.h"
//class UACvLogin;
//class UACmUsers;
class UACcDefault {
public:
UACcDefault();
UACcDefault(int iMaxLogin, UACmUsers* mUsers = nullptr, UACvLogin* viewLogin = nullptr);
virtual ~UACcDefault();
int GetUserid() const;
void SetUserid(int userid);
const wxString& GetUsername() const;
void SetUsername(const wxString& username);
const wxString& GetPassword() const;
void SetPassword(const wxString& password);
int GetContactid() const;
void SetContactid(int contactid);
bool GetLoggedIn();
protected:
private:
UACmUsers* mUsers;
UACvLogin* viewLogin;
int iMaxLogin;
};
#endif //MANAGER_UACCDEFAULT_H
The error messages are:
src/UAC/controllers/UACcDefault.h(19): error C2061: syntax error: identifier 'UACvLogin'
src/UAC/controllers/UACcDefault.h(37): error C2143: syntax error: missing ';' before '*'
src/UAC/controllers/UACcDefault.h(37): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
src/UAC/controllers/UACcDefault.h(37): error C2238: unexpected token(s) preceding ';'
I researched the codes, C2061, C2143, C4430, C2238, and they indicate the compiler is not detecting that UACvLogin has been declared, earlier.
Whenever I take steps to mitigate these errors, such as change the code so UACvLogin is not a pointer, I get these error messages:
src/UAC/controllers/UACcDefault.h(37): error C3646: 'viewLogin': unknown override specifier
src/UAC/controllers/UACcDefault.h(37): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
The compiler is now focusing on the name (viewLogin) of the variable, instead of the type. If I remove UACvLogin* viewLogin from the header file (the variable is currently used in only one method), or un-comment the class UACvLogin; line, the compiler changes its focus to the UACmUsers identifier:
src/UAC/controllers/UACcDefault.h(36): error C2143: syntax error: missing ';' before '*'
src/UAC/controllers/UACcDefault.h(36): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
src/UAC/controllers/UACcDefault.h(36): error C2238: unexpected token(s) preceding ';'
If I un-comment both class declarations, class UACvLogin; and class UACmUsers;, the compiler complains about the SOCI library. I will not quote the error messages, here.
I performed a build with the /P option to see the preprocessor output and the includes are putting the class declarations where they should be: before they are used/referenced in the the UACcDefault class.
Can someone help me find the cause of this error?
The entire project is on GitHub.
src\includes.h../views/UACvLogin.h=src\UAC\views\UACvLogin.h../models/UACmUsers.h=src\UAC\models\UACmUsers.hcmake-build-debug-msvc-2019/UACvLogin.i10.2MB This file shows the preprocessor output forUACvLogin.cpp.cmake-build-debug-msvc-2019/UACmUsers.i10.2MB This file shows the preprocessor output forUACmUsers.cpp.cmake-build-debug-msvc-2019/UACcDefault.i10.2MB This file shows the preprocessor output forUACcDefault.cpp.
The circular
#includescame from having aincludes.h, which also includedmain.h.The
includes.hfile had everything needed by most of the code: wxWidgets, boost::propertytree, SOCI. Due to needing access to some global variables (preferences),main.hwas also included.I have refactored
includes.hinto separate files for each library. Only the models (I am using Model-View-Controller architecture) need access to SOCI.I have moved the preferences data and methods to a separate class with static members. This cleans up MyApp and eliminates the need to include
main.h. I am able to stream-line access to each preference setting and reading and writing the preferences data file. Only this class needs access to boost::propertytree.