I'm pretty proficient with Java but am not sure what's going on with pointers, classes, or imports/includes in C++. I originally had a size() function but I was getting error about it conflicting with my 'int size;' variable. Can functions not share the same name as variables? I renamed it to getsize but I'm still not sure why this isn't working or what exactly is going on. Error message at bottom.
Not real sure what #ifndef/#define/#endif are for exactly either. Seems to be a safeguard so that files aren't included twice?
THANKS!
main.cpp
#include <iostream>
#include "LList.h"
using namespace std;
int main() {
cout << "Hello World" << endl;
LList* l = new LList();
cout << l->getsize() << endl;
return 0;
}
LList.h
#ifndef LLISTH
#define LLISTH
class LList {
private:
int size;
public:
LList();
int getsize();
};
#endif
LList.cpp
#ifndef LLISTCPP
#define LLISTCPP
#include "LList.h"
LList::LList() {
this->size = 0;
}
int LList::getsize() {
return this->size;
}
#endif
[bletchley@mikey test]$ g++ main.cpp LList.cpp -o -Wall Main
Error:
main.cpp: In function âint main()â:
main.cpp:10: error: request for member âgetsizeâ in âlâ, which is of non-class type âLList ()()â