P
plug.gulp
Hello,
I am learning C++. I wrote the following C++ code to understand namespace and inheritance. It does not compile(g++ 4.6.3), but when I explicitly specify the scope resolution the program works. Why am I not able to directly call the public method implemented in the base class?
namespace N1 {
class C
{
public:
void F(const std::string& s)
{
std::cout << "N1::C::F(str): " << s.c_str() << std::endl;
}
};
};
namespace N2 {
class C : public N1::C
{
public:
void F(int i)
{
std::cout << "N2::C::F(int): " << i << std::endl;
}
};
};
int main()
{
N2::C c;
c.F(1);
// The following statement does not compile unless
// it is called with full scope resolution as follows:
// c.N1::C::F("one");
c.F("one");
return 0;
}
Thanks and regards,
Plug
I am learning C++. I wrote the following C++ code to understand namespace and inheritance. It does not compile(g++ 4.6.3), but when I explicitly specify the scope resolution the program works. Why am I not able to directly call the public method implemented in the base class?
namespace N1 {
class C
{
public:
void F(const std::string& s)
{
std::cout << "N1::C::F(str): " << s.c_str() << std::endl;
}
};
};
namespace N2 {
class C : public N1::C
{
public:
void F(int i)
{
std::cout << "N2::C::F(int): " << i << std::endl;
}
};
};
int main()
{
N2::C c;
c.F(1);
// The following statement does not compile unless
// it is called with full scope resolution as follows:
// c.N1::C::F("one");
c.F("one");
return 0;
}
Thanks and regards,
Plug