P
PengYu.UT
I try to invoke the [] operator of the base class.
** line doesn't work. But *** line works. However, *** lines becomes
problematic with multiple inheritance is used for "derived". ****
works, but it is a little bit cumbersome. I'm wondering if there any
way to make ** works?
#include <iostream>
#include <cstring>
class base {
public:
int operator[](int i) {
return i;
}
int get(int i) {
return i;
}
};
class derived : private base {
public:
derived(int i) {
std::cout << "base: " << base << std::endl; //error
**
std::cout << "base: " << (*this) << std::endl; //no error
***
std::cout << "base: " << base:
perator[](i) << std::endl;//
no error ****
std::cout << "base.get(i): " << base::get(i) << std::endl;
}
};
int main(int argc, char *argv[])
{
derived a(10);
}
** line doesn't work. But *** line works. However, *** lines becomes
problematic with multiple inheritance is used for "derived". ****
works, but it is a little bit cumbersome. I'm wondering if there any
way to make ** works?
#include <iostream>
#include <cstring>
class base {
public:
int operator[](int i) {
return i;
}
int get(int i) {
return i;
}
};
class derived : private base {
public:
derived(int i) {
std::cout << "base: " << base << std::endl; //error
**
std::cout << "base: " << (*this) << std::endl; //no error
***
std::cout << "base: " << base:
no error ****
std::cout << "base.get(i): " << base::get(i) << std::endl;
}
};
int main(int argc, char *argv[])
{
derived a(10);
}