i am trying to use a pointer variable in a class but instead it gave me an error
Car.cpp:15:16: error: right hand operand to ->* has non-pointer-to-member type 'int *' return this->*tires;
here is my program
main.cpp
#include <iostream>
#include "Car.h"
using namespace std;
int main(){
int x = 5;
Car honda("honda", &x);
cout << honda.getBrand() << " " << honda.getTires() << endl;
x = 6;
cout << honda.getBrand() << " " << honda.getTires() << endl;
return 0;
}
Car.h
#ifndef CAR_H
#define CAR_H
#include <string>
using namespace std;
class Car {
private:
string brand;
int *tires;
public:
Car(string brand, int *tires);
string getBrand();
int getTires();
};
#endif
Car.cpp
#include "Car.h"
using namespace std;
Car::Car(string brand, int *tires){
this->brand = brand;
this->tires = tires;
}
string Car::getBrand(){
return this->brand;
}
int Car::getTires(){
return this->*tires;
}
on Car.cpp the method Car::getTires lies the error which seems to already be logical, i tried to use this->tires or this->(*tires) but it still gave me error.