Reputation: 23
I just switched from Python to C++. This is a practice I did for struct
. There's always an error 'incomplete type is not allowed' if I don't directly use struct at the source file.
I have review many answers at stack overflow and tried to add typedef
in header or remove struct at std::vector<double> timesteps(struct temporal_info time)
, but none of them work.
Here's my dmdbase.h
#ifndef dmdbase
#define dmdbase
#include <iostream>
#include <vector>
class DMDBase
{
public:
struct temporal_info
{
double t0;
int trend;
double dt;
};
std::vector<double> timesteps(struct temporal_info time);
};
#endif
Here's my dmdbase.cpp
using namespace std;
std::vector<double> timesteps(struct temporal_info time)
{
std::vector<double> time_map;
double final = time.trend + time.dt;
for (double t = time.t0; t < final; t += time.dt)
{
time_map.push_back(t);
}
return time_map;
}
Upvotes: 2
Views: 827
Reputation: 2804
In dmdbase.cpp
make sure you specify that timesteps
is a method of DMDBase
class.
And remove struct
keyword before temporal_info
as it was already mentioned.
std::vector<double> DMDBase::timesteps(temporal_info time)
{
...
}
The emphasis is on DMDBase::timesteps
Upvotes: 3
Reputation: 393
You don't need the struct keyword in the function call site, that is not part of the type
std::vector<double> timesteps(temporal_info time);
Also: Issue is struct 'temporal_info' only defined inside the DMDBase class. So you have to do this
std::vector<double> DMDBase::timesteps(temporal_info time);
Upvotes: 4
Reputation: 1276
try this
#include <iostream>
#include <vector>
typedef struct temporal_info temporal_info;
class DMDBase
{
public:
struct temporal_info
{
double t0;
int trend;
double dt;
};
std::vector<double> timesteps(temporal_info time);
};
Upvotes: -2