error: request for member 'sitForExam' in 'Ben', which is of non-class type 'BigData*'

 This error is so obvious but I wanted to record it in the blog, so here is an another post. 

#include <iostream>
using namespace std;

class Subjects {
public:
    void learnToCode() {cout << "Subjects : Learn to Code" << endl;};
    void sitForExam() {cout << "Subjects : Sit for Exam" << endl;};
};

class Physics : public Subjects {
public:
    void sitForExam() {cout << "Physics: Sit for Exam" << endl;};
    void learnRProgram() {cout << "Physics : Learn R Programming" << endl;};   
};

class BigData : public Physics {
public:
    void learnToCode() {cout << "BigData : Learn to Code" << endl;};
    void learnRProgram() {cout << "BigData : Learn R Programming" << endl;};
};

class CloudComputing : public Subjects {
public:
    void learnToCode() { cout << "CloudComputing : Learn to Code" << endl;};
    void sitForExam() { cout << "CloudComputing : Sit for Exam" << endl;};
};
int main() { Physics *pilot = new Physics; BigData *Ben = new BigData; CloudComputing *Clara = new CloudComputing; Ben.sitForExam(); /* Physics: Sit for Exam */ Clara.learnToCode(); /* CloudComputing : Learn to Code */ pilot.sitForExam(); /* Physics: Sit for Exam */ Ben.learnToCode(); /* BigData : Learn to Code */ Clara.learnRProgram(); /* Doesn't compile */ pilot.learnRProgram(); /* Physics : Learn R Programming */ return 1; }


Output:

1
2
3
In function 'int main()':
Line 33: error: request for member 'sitForExam' in 'Ben', which is of non-class type 'BigData*'
compilation terminated due to -Wfatal-errors.

This will be resolved easily by changing all the "." to "->". 





Comments