Hello guys,
I'm both new to linux and c++, and I have problems compiling and running my elementary c++ program in shell;
I keep getting this error whatever I do...
Here is the code:
---Second.h----
-----Second.cpp-----
-----Main.cpp-----
In shell I used "g++ Main.cpp" than I had the error above, instead of the file a.out, I think this occurs because it uses gcc instead of g++ but I dunno what to do, any bit of help is appreciated, thanks for your answers.
I'm both new to linux and c++, and I have problems compiling and running my elementary c++ program in shell;
Code:
Main.cpp:(.text+0x1a2): undefined reference to `Second::Second(int)' Main.cpp:(.text+0x1b5): undefined reference to `Second::setNumber(int)' Main.cpp:(.text+0x1c0): undefined reference to `Second::printStuff()'
Here is the code:
---Second.h----
Code:
#include <iostream>
using namespace std;
class Second
{
public:
Second( int );
void printStuff();
void setNumber( int );
private:
int number;
};
-----Second.cpp-----
Code:
#include <iostream>
using namespace std;
#include "Second.h"
Second::Second(int a)
{
setNumber( a );
}
void Second::printStuff()
{
cout << "The number is: " << number << endl;
}
void Second::setNumber( int c )
{
number = c;
}
Code:
#include "Second.h"
int main()
{
int g = 6;
Second obj(g);
obj.printStuff();
obj.setNumber(4);
obj.printStuff();
return 0;
}


Comment