Compile error when using QUERY like in documentaion described - c++

I'm following the documentation and got an error during compilation following example:
https://oatpp.io/docs/components/api-controller/#query-parameters-mapping
Visual Studio 2017 is complaining about C2839:invalid return type 'type' for overloaded 'operator ->' and C2232 '->' : left operand has 'class-key' type, use '.' when I try to use age like mentioned in the example.
ENDPOINT("GET", "/users", getUsers,
QUERY(Int32, age))
{
OATPP_LOGD("Test", "age=%d", age->getValue());
return createResponse(Status::CODE_200, "OK");
}
What's wrong with the usage/example?

Documentation is outdated, solution is:
OATPP_LOGD("Test", "age=%d", *age);

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++ compile error C4430, C2653, C2146, C2143

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?

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 on Visual C++ Forms, Simple MessageBox and assign text from textfield to string

private: System::Void btn_entrar_Click(System::Object^ sender, System::EventArgs^ e) {
string btn_texto = txt_login->Text->ToString();
MessageBox(NULL, "Hello!", btn_texto.c_str(), MB_OK | MB_ICONEXCLAMATION);
}
I'm creating a windows forms application normally in Visual C++ Studio 2008 Professional, I added a click function (by double clicking in the button on the design mode) so I wrote the code inside the function it generated.
it generated 2 errors:
Error 1:
error C2440: 'initializing' : cannot convert from 'System::String ^'
to 'std::basic_string<_Elem,_Traits,_Ax>'
Error 2:
error C2872: 'MessageBox' : ambiguous symbol 1> could be
'C:\Program Files\Microsoft SDKs\Windows\v6.0A\include\winuser.h(7374)
: int MessageBox(HWND,LPCTSTR,LPCTSTR,UINT)' 1> or
'c:\windows\microsoft.net\framework\v2.0.50727\system.windows.forms.dll
: System::Windows::Forms::MessageBox'
I'm creating in C++ on Visual Studio 2008 Professional at Windows 7 and the project under .NET Framework 3.5
Someone know how do I fix this? I looked it up all over but couldn't find a solution.
I hope I gave enough information.
Thanks in advance.
#edit Example Given by Cody Gray
System::String btn_texto = txt_login->Text->ToString();
System::Windows::Forms::MessageBox(NULL, "Hello!", "HI", MB_OK | MB_ICONEXCLAMATION);
Errors Gotten
error C3149: 'System::String' : cannot use this type here without a
top-level '^' error C2661:
'System::Windows::Forms::MessageBox::MessageBox' : no overloaded
function takes 4 arguments
So I solved the first error by adding ^ after System::String
being like this:
System::String^ btn_texto = txt_login->Text->ToString();
but the second error wasn't fixed, and by the way, how would I add the "btn_texto" content in the MessageBox Function? Thanks!
System::String^ btn_texto = txt_login->Text->ToString();
MessageBox::Show( "Working", "Info", MessageBoxButtons::OK, MessageBoxIcon::Exclamation );
Solved it. :)
You're mixing C++ string types (std::string) and .NET Framework string types (System::String) all over the place, and that's just not going to work out well. Or at least it's not going to be very simple. Decide which one you want to use and stick with it.
More specifically, the first error is caused by this line being wrong:
string btn_texto = txt_login->Text->ToString();
The first reason it's wrong is because it creates an object of type std::string (presumably, you have a using namespace std; statement at the top of your code file), which is the C++ string type, not the .NET Framework string type. The .NET Framework string type is the one that you'll probably want to use in a .NET WinForms application. You'll have to fully qualify the namespace as System::String.
The second reason it's wrong is because it's pointless to convert a String object (as returned by the Text property) to a String object using the ToString() method. Leave that last function call off completely.
The second error is caused by the fact that the Win32 headers provide a MessageBox function, as does the .NET Framework. The compiler needs to know which one you want to call.
To call the Win32 MessageBox function (like you're attempting to do now), you need to use the global scope resolution operator: ::MessageBox.
But then you're going to run into the problem of not being able to convert from System::String into a C-style string. See this article for instructions on how to convert between the various string types available in C++/CLI.
The simpler approach is probably to call the .NET version of the MessageBox function, which you can accomplish by fully qualifying like so: System::Windows::Forms::MessageBox. The advantage of this version is that you won't need to do any string conversion because it accepts a parameter of type System::String. The .NET MessageBox wrapper supports all the same options as the Win32 MessageBox function, but some of them are in a different order, so you'll need to pay careful attention to the documentation.

C++ Does Not Name A Type

I get confused when I get errors like these
I have
FxSmartPtr<FxStreamable> able(FcNew,stream->StreamInObject());
FxGlobalPair pair(id,able);
I get an error on FxGlobalPair pair(id,able); that is able is not a type.
I tried modifying to
FxGlobalPair pair(id,FxSmartPtr<FxStreamable>::able);
but I get an error that is error: 'class FxSmartPtr<FxStreamable>::able' has not been declared
What concept am I missing?
UPDATE: typedef pair<FxID, FxSmartPtr<FxStreamable> > FxGlobalPair;
UPDATE 2:
Heading
I think that you have found the Most Vexing parse
The problem is that
FxSmartPtr able(FcNew,stream->StreamInObject());
may define a function named able, instead of a variable.