I'm getting this error:
<source>:48:32: error: use of deleted function 'FPTask_sim::Data_T::Data_T()'
48 | FPTask_sim::Data_T FPTask_sim::_data;
| ^~~~~
<source>:40:9: note: 'FPTask_sim::Data_T::Data_T()' is implicitly deleted because the default definition would be ill-formed:
40 | } Data_T;
| ^~~~~~
You can recreate the error using stripped version of my code:
(NOTE: comment the "#define BREAK_EVERYTHING" and the code will compile)
#define BREAK_EVERYTHING
namespace tinyfsm
{
struct Event {};
}
namespace EventConsts
{
struct EventCode_T {};
struct Event_T {};
struct EventStruct_T : tinyfsm::Event
{
#ifdef BREAK_EVERYTHING
EventStruct_T(const Event_T& Event);
#else
struct Event { };
#endif
};
}
class FPTask_sim
{
public:
FPTask_sim();
typedef struct
{
tinyfsm::Event ARG_react_01_unused_arg01;
EventConsts::EventStruct_T ARG_react_02_unused_arg01; // These lines seem to be causing the issue
EventConsts::EventStruct_T ARG_dispatch_e; // These lines seem to be causing the issue
} Data_T;
static Data_T _data;
static Data_T _call_data;
};
FPTask_sim::Data_T FPTask_sim::_data;
int main()
{
bool exampleVariable;
}
I'm thinking this is being caused by the
EventStruct_T(const Event_T& Event);
line, specifically because its being passed by reference and the overall object "_data" is static. Not sure how to fix this though.
Thanks!
EDITS:
Sorry, forgot to include the constructor that is in it already. It looks like it just copies the Event_T obj to EventStruct_T. If Im understanding what you are saying, I need to either give values when declaring the object or add in the blank default constructor. Right?
#define BREAK_EVERYTHING
namespace tinyfsm
{
struct Event {};
}
namespace EventConsts
{
struct Event_T {bool a;};
struct EventStruct_T : tinyfsm::Event
{
bool a;
#ifdef BREAK_EVERYTHING
//EventStruct_T(){} // New default constructor?
EventStruct_T() = default; // Answer provided by user17732522
EventStruct_T(const Event_T& Event);
#else
struct Event { };
#endif
};
}
class FPTask_sim
{
public:
FPTask_sim();
typedef struct
{
tinyfsm::Event ARG_react_01_unused_arg01;
EventConsts::EventStruct_T ARG_react_02_unused_arg01; // These lines seem to be causing the issue
EventConsts::EventStruct_T ARG_dispatch_e; // These lines seem to be causing the issue
} Data_T;
static Data_T _data;
static Data_T _call_data;
};
FPTask_sim::Data_T FPTask_sim::_data;
int main()
{
bool exampleVariable;
}
// Current constructor in separate file
EventConsts::EventStruct_T::EventStruct_T(const EventConsts::Event_T& Event) :
a(Event.a),
{}
CodePudding user response:
If you declare any constructor for a class, then the default constructor (constructor not requiring any argument) will not be declared implicitly.
So then there is no constructor to construct e.g. FPTask_sim::_data.ARG_react_02_unused_arg01
when you are trying to initialize it without constructor argument in FPTask_sim::Data_T FPTask_sim::_data;
.
Either provide arguments to the initializer of FPTask_sim::_data
so that FPTask_sim::_data.ARG_react_02_unused_arg01
and the other are given arguments from which they can be constructed, give them default-initializers in the definition of EventStruct_T
or define a default constructor for EventStruct_T
yourself.