reference to non static member function?
Mar 8, 2018 at 6:48pm UTC
I'm testing out classes, and I'm confused on how to get past the error:
"reference to non-static member function must be called; did you mean to call it with no arguments?"
Dog.h
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
#ifndef DOG_H_INCLUDED
#define DOG_H_INCLUDED
#include <iostream>
using namespace std;
class Dog
{
public :
typedef std::size_t size_type;
static const size_type CAPACITY = 200;
Dog() : used(0) {}
string GetData(){return data[used];}
void insert(const string entry);
private :
string data[CAPACITY];
size_type used;
};
#endif // DOG_H_INCLUDED
Dog.cpp
1 2 3 4 5 6 7 8 9 10
#include "Dog.h"
void Dog::insert(const string entry) {
data[used] = entry;
++used;
}
main.cpp
1 2 3 4 5 6 7 8 9 10 11 12 13
#include <iostream>
#include "Dog.h"
using namespace std;
int main()
{
cout << "Hello world!" << endl;
Dog dog;
dog.insert("pomeranian" );
cout << dog.GetData;
return 0;
}
Mar 8, 2018 at 6:54pm UTC
Tried "static void insert ..." already?
Mar 8, 2018 at 7:00pm UTC
Try posting the ENTIRE error message you get.
Mar 8, 2018 at 7:06pm UTC
@FurryGuy
main.cpp|11|error: reference to non-static member function must be called; did you mean to call it with no arguments?|
Mar 8, 2018 at 7:11pm UTC
In main.cpp line 11 should be cout << dog.GetData();
Mar 8, 2018 at 7:11pm UTC
No, the ENTIRE error message your compiler is showing.
something like this:
1>6-4_AmbiguousStatements.cpp
1>6-4_AmbiguousStatements.cpp(18): error C2065: 'cout': undeclared identifier
is much more helpful to figuring out what is wrong than what you post.
Mar 8, 2018 at 7:18pm UTC
cout << dog.GetData;
should be cout << dog.GetData();
GetData()
is a class member function, not a class variable.
Topic archived. No new replies allowed.