I have 3 classes, lets say ClassA, ClassB and Validator. I want to pass one variable of both classA and classB to the Validator, which will compare the values, and return a string result. I get the following error: error:
request for member ‘compareValues’ in ‘validatorObject’, which is of non-class type ‘Validator*’
main.cpp
cout << classAobject.compareValues(computer1->getValue(), classBobject->getValue());
validator.cpp
string Validator::compareValues(string classAvalue, string classBValue) {
if (classAvalue == "R") {
if (classBvalue == "R") {
return "Equal";
}
}
// More will go in this function - just want to get it working first
}
validator.h
string compareValues(string classAvalue, string classBValue);
This error appear because you need to access class member from pointer to class by using
->operator:cout << classAobject->compareValues(.....)Foo->bar()is equivalent to(*Foo).bar(), andFoo->bazis equivalent to(*Foo).baz