Good day all
note: I am a begginer at c++, teaching myself as I go along, also apologies if this is a duplicate, but I have not found an example/answer/tutorial to answer question, possibly I just do not understand it yet.
I have a function with header and implementation defined below:
Header
#ifndef RETURNOBJECT_H
#define RETURNOBJECT_H
#include <QtCore>
#include "enums.h"
class ReturnObject
{
public:
ReturnObject();
ReturnObject(ReturnCode enum_code, const char data);
const char getData();
ReturnCode getCode();
private:
ReturnCode e_code;
const char data_string;
};
#endif // RETURNOBJECT_H
Implementation
#include "returnobject.h"
ReturnObject::ReturnObject(){
data_string="WARN";
}
ReturnObject::ReturnObject(ReturnCode enum_code, const char data)
: e_code(enum_code)
, data_string(data)
{}
ResultCode ReturnCode::getCode()
{
return e_code;
}
const char ReturnObject::getData()
{
return data_string;
}
Please note, I am not as familiar with pointers,etc as I should be but I have a fair understanding of each concept.
Purpose:
This object is created by a custom class function, stored within the class and returned to the parent class. The object contains a custom exec()
return value and possible output message/data from the class ( I created this, due to the limited restrictions on e.g. QDialog.setResult()
allowing only a exec()
return result of 1 or 0).
Issue/Problem/Question
calling the class with:
Private
ReturnObject _ReturnObject;
_ReturnObject = new ReturnObject(ReturnCode::LoginDialog_EmptyLoginPass, "");
provides the following error:
/home/cx/qt-projects/project-i/loginstatusdialog.cpp:21: error: invalid conversion from 'const char*' to 'char' [-fpermissive]
_ReturnObject = new ReturnObject(ReturnCode::LoginDialog_EmptyLoginPass, "");
^
Thus, I conclude from the error that the second parameter -> ""
or data
is the issue as I, most probably, do not properly define this datatype in the constructor.
How should I define this in the constructor?, rather which data type does ""
use? As I understand, it does take on a const
property.
What I have tried:
I have attempted using char
, const char
, QString
both which give a similar error.
Any suggestions?
Compiler output
after solution of const char * data
../project-i/loginstatusdialog.cpp: In constructor 'LoginStatusDialog::LoginStatusDialog(QString, QString, QString*, QWidget*)':
../project-i/loginstatusdialog.cpp:21:44: error: use of deleted function 'ReturnObject& ReturnObject::operator=(ReturnObject&&)'
_Return_Object = ReturnObject(1, "");
^
In file included from ../project-i/loginstatusdialog.h:10:0,
from ../project-i/loginstatusdialog.cpp:1:
../project-i/returnobject.h:7:7: note: 'ReturnObject& ReturnObject::operator=(ReturnObject&&)' is implicitly deleted because the default definition would be ill-formed:
class ReturnObject
^~~~~~~~~~~~