G
gyan
Please go though following program:
#include <iostream.h>
class base {
public:
int basepublic;
protected:
int baseprotected;
};
class derived : public base {
public:
void compare(const derived *pb){
int a=pb->basepublic;
a=pb->baseprotected;
}
};
int main(){
return 0;
}
Now when i compile and run this program, it got all through.
MY question is how it is possible to access protected variable of a
different derive object in derive class's member function?
if i change argument of compare function from
const derived *pb to
const base *pb,
i get compilation error
" "1.cpp", line 14: Error: baseprotected is not accessible from
derived::compare(const base*)."
which is expected.
#include <iostream.h>
class base {
public:
int basepublic;
protected:
int baseprotected;
};
class derived : public base {
public:
void compare(const derived *pb){
int a=pb->basepublic;
a=pb->baseprotected;
}
};
int main(){
return 0;
}
Now when i compile and run this program, it got all through.
MY question is how it is possible to access protected variable of a
different derive object in derive class's member function?
if i change argument of compare function from
const derived *pb to
const base *pb,
i get compilation error
" "1.cpp", line 14: Error: baseprotected is not accessible from
derived::compare(const base*)."
which is expected.