May 17, 2013 at 6:19am UTC
I'd like to implement a function from SolsticeClass.ccp into main.cpp by first prototyping it in SolsticeClass.h inside the class, and then creating an object. However, I don't know how to correctly write the function out before prototyping it. The constructor works perfectly fine, though.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46
Here's main .cpp:
#include <iostream>
#include "SolsticeClass.h"
using namespace std;
int main()
{
SolsticeClass s;
s.saying();
return 0;
}
Here' s SolsticeClass.cpp:
#include "SolsticeClass.h"
#include <iostream>
using namespace std;
SolsticeClass::SolsticeClass()
{
cout << "Hello from the constructor!" << endl;
}
void saying()
{
cout << "Hello from the other function!" << endl;
}
and finally, SolsticeClass.h:
#ifndef SOLSTICECLASS_H
#define SOLSTICECLASS_H
class SolsticeClass
{
public :
void saying();
SolsticeClass();
};
#endif
The error message it gives me is as follows:
undefined reference to 'SolsticeClass::saying()'
Last edited on May 17, 2013 at 6:20am UTC
May 17, 2013 at 6:33am UTC
In your source file just write the function like you did the constructor, i.e.:
void SolsticeClass::saying()
May 17, 2013 at 6:46am UTC
Awesome, thanks guys :)
Didn't know the return type needed to be before the scope operator thing.
Last edited on May 17, 2013 at 6:51am UTC