I have a class defined in a separate file and at some point I need to access one of the public member functions from another source file. For some reason, I forgot how to do that and compiler gives me an error.
I have classA.h with definition of class A similar to this:
class classA {
public:
int function1(int alpha);
}
And a separate file classA.cpp with the implementation. And then in some other file blah.cpp I include the header and try to access it like this:
classA::function1(15);
and my compiler refuses it with error that it could not find a match for ‘classA::function1(int)’.
I use Embarcadero RAD studio 2010 if that matters.
To call a ‘normal’ function, you need an instance.
If you want to call the function using
classA::then it needs to bestatic.Note that inside a static method, you can’t access any non-static member variables, for the same reason – there is no instance to provide context.