How exciting.
I'm really bored so I'm attempting to learn some basic C++
I'm making a simple class that attempts to store a mighty 1 string. Good for it yeah? Hahaha
To bad I get compile time errors and I don't know what the hell they mean.
Here's MyObj.h
Fun hey?
And here's MyObj.cc
Equally exciting yeah? At least it gets to be a .cc and not just a lowly .h
An now here's the one that wears the pants in the family. The .cc with the main function in it.
Wow the other guys are really jealous of it.
Now if you aren't to exciting by this yet we are getting to the really really good part.
The compile time errors...
hugo% g++ Hello.cc
Undefined first referenced
symbol in file
MyObj::setS(char *) /var/tmp/ccnaOJnX.o
MyObj::getS(void) /var/tmp/ccnaOJnX.o
MyObj::MyObj(int) /var/tmp/ccnaOJnX.o
ld: fatal: Symbol referencing errors. No output written to a.out
collect2: ld returned 1 exit status
And as I'm typing this I realize that I need to compile the two togeter with a g++ *.cc
Oh...my constructor and destructor need to be member functions...good for them.
Yup now a g++ *.cc works fine and running a.out gives me Hello World.
Yup good for it.
Thanks for coming on this fun ride with me.
I'm going to play with C++ some more...so just wait I'm sure I'll have more fun stuff to post.
I'm really bored so I'm attempting to learn some basic C++
I'm making a simple class that attempts to store a mighty 1 string. Good for it yeah? Hahaha
To bad I get compile time errors and I don't know what the hell they mean.
Here's MyObj.h
class MyObj {
public:
MyObj(int n);
~MyObj();
char *getS();
void setS(char* s);
private:
char* myS;
};
Fun hey?
And here's MyObj.cc
#include "MyObj.h"
MyObj(int n) {
myS = new char[n];
}
~MyObj() {
delete myS;
}
char * MyObj::getS() {
return myS;
}
void MyObj::setS(char* s) {
myS = s;
}
Equally exciting yeah? At least it gets to be a .cc and not just a lowly .h
An now here's the one that wears the pants in the family. The .cc with the main function in it.
Wow the other guys are really jealous of it.
#include <iostream.h>
#include "MyObj.h"
void main(int argc, char *argv[]) {
MyObj *o = new MyObj(11);
o->setS("Hello World");
cout << o->getS() << endl;
}
Now if you aren't to exciting by this yet we are getting to the really really good part.
The compile time errors...
hugo% g++ Hello.cc
Undefined first referenced
symbol in file
MyObj::setS(char *) /var/tmp/ccnaOJnX.o
MyObj::getS(void) /var/tmp/ccnaOJnX.o
MyObj::MyObj(int) /var/tmp/ccnaOJnX.o
ld: fatal: Symbol referencing errors. No output written to a.out
collect2: ld returned 1 exit status
And as I'm typing this I realize that I need to compile the two togeter with a g++ *.cc
Oh...my constructor and destructor need to be member functions...good for them.
Yup now a g++ *.cc works fine and running a.out gives me Hello World.
Yup good for it.
Thanks for coming on this fun ride with me.
I'm going to play with C++ some more...so just wait I'm sure I'll have more fun stuff to post.
