Hi,
Being someone who is now working with C++ but initially started with Java, I am experiencing some problems seperating my classes from the main file.
So I want to seperate the following simple class into it's own standalone C++ file so I can use it with multiple programs:
#include <iostream>
#include <string>
using namespace std;
class signal
{
private:
int decAddress;
string binAddress;
string data;
public:
signal(string *binAddr, string *da, int decAddr)
{
binAddress = *binAddr;
data = *da;
decAddress = decAddr;
}
string getBinAddress()
{
return binAddress;
}
void setAddress(string binAddr)
{
binAddress = binAddr;
}
int getDecAddress()
{
return decAddress;
}
void setDecAddress(int decAddr)
{
decAddress = decAddr;
}
string getData()
{
return data;
}
void setData(string da)
{
data = da;
}
};
So I also created a header file to go along with it:
#include <string>
#include <iostream>
using namespace std;
class signal
{
private:
int decAddress;
string binAddress;
string data;
public:
signal(string *binAddr, string *da, int decAddr);
string getBinAddress();
void setAddress(string binAddr);
int getDecAddress();
void setDecAddress(int decAddr);
string getData();
void setData(string da);
};
In my main class, I then add the line:
#include <signal.h>
I'm using GCC to compile and run the program, so I first compile the class into an object file and recieve no errors:
g++ -c signal.cpp
Then I try to run my program linking the signal class:
g++ main.cpp -o myprogram signal.o
and I'm getting a whole bunch of errors like this:
myprogram.cpp:220: error: ISO C++ forbids declaration of `signal' with no type
Where it basically seems like my class file is still not being recognized. The problem does not have to do with the naming of my file either. Does anyone know what the problem is?
Thanks,
bleh