c++ compile error C4430, C2653, C2146, C2143 - c++

I am working on some simulation software, written in C++. Currently, when trying to build my code, I get 9 compile errors, all complaining about the three lines of code that I've just added. Those lines are the declarations in PublisherModule.h:
class PublisherModule :
public s::Module,
public s::Singleton<PublisherModule>,
public s::Interface,
public s::htmlPage{
public:
...
Types::ModeRecord;
ModeRecord modeData;
ModeRecord *modeDataPtr;
...
};
The reason for adding these declarations into the PublisherModule.h was so that I could add the following code into the publish() function of the PublisherModule.cpp file:
Types::ModeRecord ModeData;
Types::ModeStatusRecord *ModeDataPtr = &ModeData;
DataStore->getModeData(*ModeDataPtr);
The publish() function now looks like this:
void PublisherModule::publishData(void){
...
Types::ModeRecord ModeData;
Types::ModeStatusRecord *ModeDataPtr = &ModeData;
DataStore->getModeData(*ModeDataPtr);
...
}
The errors that the compiler is giving me are:
error C2653: 'Types': is not a class or namespace name
error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
error C2146: syntax error : missing ';' before identifier 'ModeData'
error C2143: syntax error : missing ';' before '*'
I get error C4430 4 times in total, and the other errors all once each. They are all complaining about the lines that I added into the .h file. Having Google'd the first error, and come across this answer on SO: Compiler error C2653: not a class or namespace name , it would appear that the cause is a circular dependency in the header files...
But that is not happening here as far as I can tell... Are there any other reasons why I might get this compile error, and what's preventing my code from building?
The message displayed when I hover my cursor over the first line that I've added in the .h file, Types::ModeRecord is:
Error: a class-qualified name is required

Here is an abbreviated version of the code you posted, with my observation:
class PublisherModule [... bunch of base classes...]
{
public:
Types::ModeRecord;
};
What do you think this line does??
Types::ModeRecord;
It is not of the form [TypeName] [VariableName]; (eg int i;)
It does not look like a method prototype (eg void foo(int i);)
It is not a typedef.
It doesn't look like any normal C++.
What do you think it is doing?

Related

Using Steamworks in Unreal Engine 4

So I've started implementing Steamworks functions for my game, and everything went perfectly fine. I managed to get sync with steam API ( i can do achievements and see that i'm playing game on my steam acc). However when i wanted to start using some functions that they provided, my engine is saying:
error LNK2019: unresolved external symbol
Anyone can help me solve this problem? I'm aiming atm at reading and saving score in Leaderboards. Any good advices for me ? :D
Code sample that gives me error:
int MyCodeLibrary::TryGetScore()
{
if (SteamAPI_Init())
{
CSteamLeaderboards obj();
obj().FindLeaderboard("test");
obj().DownloadScores();
return 0;
}
else
{
return 0;
}
}
Also tried to get to Steam with OnlineSubsystem like this:
void MyCodeLibrary::UpdateScoreInt(int score, FName board, APlayerController* PlayerController)
{
OutputDebugStringA("Funkcja jest wywoływana");
if (SteamAPI_Init())
{
OutputDebugStringA("Steam API działa");
ULocalPlayer* LocalPlayer = Cast<ULocalPlayer>(PlayerController->Player);
IOnlineSubsystem* ion = IOnlineSubsystem::Get(FName("Steam"));
TSharedPtr<const FUniqueNetId> UserId = ion->GetIdentityInterface()->GetUniquePlayerId(LocalPlayer->GetControllerId());
ion->GetLeaderboardsInterface();
FOnlineLeaderboardWrite wrt;
wrt.LeaderboardNames.Add(board);
wrt.SetIntStat(TEXT("Score"), score);
if (UserId.IsValid())
{
OutputDebugStringA("Mam UserID");
ion->GetLeaderboardsInterface()->WriteLeaderboards(board, *UserId, wrt);
printf("Odpalony score");
}
}
}
So, I've included library "steam_api64.lib" in my source, but after that i've recieved lots of error which suggest that everyting in steam_api.h is wrong :/
I'm pretty new to it, so would appreciate some furthere help with it. Here are examples of errors showing:
error C2371: "S_CALLTYPE": redefinition; different basic types
error C4430: missing type specifier-int assumed. Note C++ does not support default-int
Did I included anything wrong or missing something? Steam_api.h file is downloaded directly from steamworks and has not been modified.

C++ undeclared identifier when trying to create an instance of a struct

I have a struct that is declared in a C++ header file with the line:
struct AII_Common_Export message{
...
};
I am then trying to create an instance of that struct in a C++ source file, so that I can set/ use some of the attributes stored in the struct:
message data;
However, when I compile my code, I get an "undeclared identifier" error on this line... I have included the header file in the source file, so I don't understand why I am getting this error- can someone explain it to me?
I also tried creating the instance of it with:
AII_Common_Export message data;
But then got the compile error: "syntax error: missing ';' before identifier 'data'.
Any ideas how I can fix this, so that I can create an instance of the struct?
EDIT
I have just found the AII_Common_Export definition- it is defined with:
# define AII_Common_Export ACE_Proper_Import_Flag
and the ACE_Proper_Import_Flag is defined with:
#define ACE_Proper_Import_Flag __declspec (dllimport)
These two definitions are in separate header files.
Just do.
struct message{
...
};
message data;
see http://www.cplusplus.com/doc/tutorial/structures/

Add a header to a cppnet-lib response object

I would like to add a header to a cppnet-lib basic_response object. However, I am getting compilation errors.
I can add a header to a basic_request as follows which compiles ok:
boost::network::http::basic_request<boost::network::http::tags::http_server> request;
request << header("test", "test");
However, doing the same for a response object as follows receives a compilation error:
boost::network::http::basic_response<boost::network::http::tags::http_server> response;
response << header("test", "test");
Compilation error:
'headers_container_type': the symbol to the left of a '::' must be a type (header.hpp)
'value_type': is not a member of boost::network::http::basic_response<boost::network::http::tags::http_server> (header.hpp)
syntax error: missing ';' before identifier 'value_type' (header.hpp)
This would suggest that this isn't possible on a response object, but following the following page seems to suggest it is. I'm obviously going wrong somewhere!
Documentation: http://cpp-netlib.org/0.8/reference_http_response.html
My environment is:
Visual Studio 2013 (building as Release)
Boost 1.55
cppnet-lib: 0.11.0
Any help would be very much appreciated! Thanks.
First, I think you're using the wrong documentation since you're using version 0.11.0 (I suggest you use 0.11.1, which has a lot of bug fixes on top of 0.11.0). Here's the link you actually want for the 0.11.0 documentation:
http://cpp-netlib.org/0.11.0/reference/http_server.html#response-object
Second, you'd want to add headers directly to the response object's headers member. No need to use functions to do this:
struct my_server {
void operator(server::request const& req, server::response & res) {
// do something with the request and/or response
res.headers.push_back(server::response::header("Name", "value"));
// do more things
}
// ...
};

Error Add Class from another project in the same solutions C++

I'm just beginning to write code with C++, and I got stuck when I want to add reference to class from other project from the same solutions.
my Main code located at :
InventoryAppDLL (contains code to access Sql Database)
class : dbConnection.h
Code:
ref class dbConnection
{
public:
dbConnection();
void SetCommandText(String ^command,bool ^commandText);
int ExecuteScalar();
DataSet^ ExecuteDataSet();
DataTable^ ExecuteDataTable();
protected:
~dbConnection();
private:
DbConnection ^conn;
DbCommand ^cmd;
ConnectionStringSettings ^settings;
DbProviderFactory ^fac;
};
after i build the main project (InventoryAppDLL), it was success and contains no errors.
but after I include the header into another project (InventoryAppService),and then I build it, it contains error :
error C2143: syntax error : missing ';' before '^'
when I reference to the error, I've got ConnectionStringSettings missing library on dbConnectionClass (InventoryAppDLL).
private:
DbConnection ^conn;
DbCommand ^cmd;
ConnectionStringSettings ^settings; // <---
DbProviderFactory ^fac;
};
I think you don't even need to include the header file. Since you have already added a reference from the consuming project to the project containing this class, the consuming project can read the metadata from the DLL project and you can simply say:
auto x = ref new dbConnection();

Enterprise Architect Reverse Engineering: 'Unexpected symbol' error

I'm trying to generate a class diagram, using reverse engineering, but the following is happening:
There was an error parsing C:\Documents and Settings\Meus documentos\EA_Documentos\Modelos\Environment\class\Factory.h on line 11. Unexpected symbol: ISIMFactory
You may need to define a language macro.
There was an error parsing C:\Documents and Settings\Meus documentos\EA_Documentos\Modelos\Environment\class\Model.h on line 99. Unexpected symbol: ISIMModel
You may need to define a language macro.
There are many more of these.
This is the corresponding code in CSIMEnvironmentModel.h
class SIMMDLENVv01_EXPORT CSIMEnvironmentModel // line 99
: public ISIMModel
, public ISIMEventSource
, public ISIMScheduledModel
, public ISIMExecut
, public ISIMPublisher
{
public:
CSIMEnvironmentModel(const std::string &a_modelType);
virtual ~CSIMEnvironmentModel(void);
and CSIMEnvFactory.h
class SIMMDLENVv01_EXPORT CSIMEnvFactory // line 11
: public ISIMFactory
{
public:
CSIMEnvFactory();
virtual ~CSIMEnvFactory(void);
std::vector<ISIMModel*> InstanceModel(const std::string &a_modelType, const std::string &a_conf);
};
What's the reason for this error message?
Your code contains usage of a macro definition (SIMMDLENVv01_EXPORT) that isn't part of EA's standard macro definitions (there's whole a lot of them covering ATL and MFC mostly).
You'll need to add additional ones under 'Settings->Language Macros' (as the hint in the error message suggests).
NOTE
Use the syntax MACRO() when declaring macros that were #defined to receive any number of arguments.
If you're trying to reverse engineer framework libraries like Qt or alike, you'll need to set many of these that you're able to reverse engineer the code without getting errors.
May be you should think of a different strategy to reference these types and classes in your model then.
Another workaround might be to solely preprocess all the code you want to import first, and import from the preprocessed results.