note: I am still new to c++, and while this may be a simple issue, yet I am unable to find a solution.
Purpose:
I would like to pass an empty string (as one would in java/C#) to my constructor. I receive an error:
error: no matching function for call to 'ReturnObject::ReturnObject(ResultCode::ClientCode, const char [1])'
return new ReturnObject(ResultCode::ClientCode::enum_FailedOpeningClientSocket, "");
The ReturnObject
's purpose is to encapsulate an enum
and a string
.
What does this error mean and how can I solve it?
I have attempted changing my constructor parameter from QString data
to char data
and calling with ''
but that resulted in an error empty character constant
.
calling code:
return new ReturnObject(ResultCode::ClientCode::enum_FailedSocketConnection, "");
header:
class ReturnObject
{
public:
ReturnObject(ResultCode enum_code, QString data);
QString getData();
ResultCode getCode();
private:
ResultCode e_code;
QString data_string;
};
implementation
#include "returnobject.h"
ReturnObject::ReturnObject(){
data_string="WARN";
}
ReturnObject::ReturnObject(ResultCode enum_code, QString data)
: e_code(enum_code)
, data_string(data)
{}
ResultCode ReturnObject::getCode()
{
return e_code;
}
QString ReturnObject::getData()
{
return data_string;
}
Thanks to wasthishelpful and a few comments, I made a tragic logic error which had me looking at the wrong parameter, the solution is that I should casting my enum class ResultCode
which is the parent class to one of the nested class
es, in this case ClientCode
, as seen below from my enum class header
enum.h
#ifndef ENUMS_H
#define ENUMS_H
class ResultCode{
public:
enum class LoginDialogCode{
enum_LoginSuccess=0,
enum_InternetOffline=1,
enum_ServerOffline=2,
enum_InvalidLoginPass=3,
enum_EmptyLoginPass=4,
enum_FailedRetreivingServerList=5,
enum_TokenFailed=6
};
enum class ClientCode{
enum_SentSuccess=10,
enum_FailedOpeningClientSocket=11,
enum_FailedClientSocketConnection=12,
enum_FailedWritingtoClientSocket=13,
enum_FailedReadingfromClientSocket=14
};
enum class ServerCode{
enum_ReceivedSuccess=20,
enum_FailedOpeningListenSocket=21,
enum_FailedBindingtoListenSocket=22,
enum_FailedAcceptingListenSocket=23,
enum_FailedWritingtoListenSocket=24,
enum_FailedReadingfromListenSocket=25
};
};
#endif // ENUMS_H