My program is returning Undefined reference to Data::init(). It's all declared correctly as far as I can tell. The method is prototyped in Data.h and filled in Data.cpp and called in main.cpp. The code was written in Visual Studio and it shows no errors with not being able to find methods.
Data.h
#ifndef DATA_H_
#define DATA_H_
#include <iostream>
#include "Controls.h"
#include "Sensors.h"
#include "Auto.h"
#include "AI.h"
class Data
{
public:
static void init();
static Sensors getSensors();
static Auto getAuto();
static Controls getControls();
static AI getAI();
private:
static Controls controls;
static Sensors sensors;
static AI brains;
static Auto auton;
};
#endif
Data.cpp
#include "Data.h"
using namespace std;
void Data::init()
{
Data::controls;
Data::sensors;
Data::brains;
Data::auton;
}
main.cpp
#include <iostream>
#include "Data.h"
using namespace std;
int main()
{
Data::init(); // Initialize Data
return 0;
}
I am compiling through cmd with g++ 4.8.1
I've tried making the method static in Data.cpp and most of the errors on the internet are due to forgetting to add the Data::
before init in the .cpp file.
CMD
g++ main.cpp
undefined reference to `Data::init()'
collect2.exe: error: ld returned 1 exit status