bug-gplusplus
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

namespaces and using


From: Kevin Hykin
Subject: namespaces and using
Date: Fri, 07 Dec 2001 18:02:45 GMT

I am not sure if this is the right place to post this.  I have a simple
program that compiles on other compilers but not using QNX qcc (which is
build on top of gcc).  If this is not
the correct place, please direct me to where it should go.

In my code I have a polymorphic method in the base class.  In the sub class
I would like to overload one of the two methods and still have access to the
other in the base class.  The below code is what I was using:

#include <stdio.h>
#include <stdlib.h>


class TestClass
{
public:
 virtual void Hello()
 {
  printf("Hello\n");
 };
 virtual void Hello(int temp)
 {
  printf("Hello with int\n");
 };
 virtual void Hello1()
 {
  printf("Hello1\n");
 };

};

class SubTestClass : public TestClass
{
public:
 using TestClass::Hello;
 void Hello(int temp)
 {
  printf("SubClassHello\n");
 };
};

class SubSubTestClass : public SubTestClass
{
public:
 using SubTestClass::Hello;
 void Hello(int temp)
 {
  printf("SubSubClassHello\n");
 };
};

int main(int argc, char *argv[])
{
 TestClass *tc;         // base class pointer
 SubTestClass *sc = new SubTestClass();   // sub class
 SubSubTestClass *ssc = new SubSubTestClass(); // subsub class

 printf("\nFirstTest, Set *tc to Subclass and print\n");
 tc = sc;  // set base class pointer to sub class
 tc->Hello();
 tc->Hello(1);
 sc->TestClass::Hello();
 sc->Hello(1);
 sc->Hello1();

 printf("\nSecondTest, Set tc to ssc and print\n");
 tc = ssc;  // set base class pointer to subsub class
 delete sc;
 sc = ssc;
 tc->Hello();
 tc->Hello(1);
 tc->Hello1();
 sc->Hello();
 sc->Hello(1);
 sc->Hello1();
 ssc->Hello();
 ssc->Hello(1);
 ssc->Hello1();
 return(0);
}

When I try to compile it I get the following errors:

[temp/inheritancetest] qcc test.cpp -lang-c++ -o test
test.cpp:31: cannot adjust access to `void TestClass::Hello(int)' in `class
SubTestClass'
test.cpp:28:   because of local method `void SubTestClass::Hello(int)' with
same name
test.cpp:41: cannot adjust access to `void SubTestClass::Hello(int)' in
`class SubSubTestClass'
test.cpp:38:   because of local method `void SubSubTestClass::Hello(int)'
with same name
test.cpp: In function `int main(int, char **)':
test.cpp:64: no matching function for call to `SubTestClass::Hello ()'
test.cpp:28: candidates are: void SubTestClass::Hello(int)
test.cpp:67: no matching function for call to `SubSubTestClass::Hello ()'
test.cpp:38: candidates are: void SubSubTestClass::Hello(int)
cc: /usr/lib/gcc-lib/ntox86/2.95.2/cc1plus error 33

I believe that the code is correct.  I have compiled it with other compilers
and it worked.  Is this just not an implemented feature or is is a bug?

Thanks,










reply via email to

[Prev in Thread] Current Thread [Next in Thread]