problem with template class and overloaded methods

G

gg

I am facing some problems with following program. I am using aCC
version 03.27 on HP-UX11. The command line I use to compile is -

aCC -AA -I. TestTempMethods.C

Can anybody pls suggest how to resolve the warnings and errors.

#include <iostream>
using namespace std;

#include <string.h>

template < class T >
class X
{
public:
virtual void foo ( );
protected:
virtual void foo ( int );
virtual void foo ( string ) = 0;
};

template < class T >
void X < T > :: foo ( )
{
foo ( 1 );
foo ( "a" );
}

template < class T >
void X < T > :: foo ( int i )
{
cout << " int " << i << endl;
}

class Y : public X < int >
{
public:
protected:
virtual void foo ( string s );
};

void Y::foo ( string s )
{
cout << " string " << s << endl;
}

int main ( void )
{
Y y;
y.foo ( );
}

The above version gives the following errors.

Error 182: "TestTempMethods.C", line 44 # "int main()" cannot access
protected member "void

Y::foo(std::basic_string said:
y.foo ( );
^^^^^^^^^
Warning 652: "TestTempMethods.C", line 29 # Virtual function "void
X<int>::foo()" is hidden by "void

Y::foo(std::basic_string said:
)"; did you forget to override it?
class Y : public X < int >
^^^^^^^
Warning 652: "TestTempMethods.C", line 29 # Virtual function "void
X<int>::foo(int)" is hidden by "void

Y::foo(std::basic_string said:
)"; did you forget to override it?
class Y : public X < int >
^^^^^^^


Just changing the Y class, gives the following errors -

class Y : public X < int >
{
public:
protected:
using X::foo;
virtual void foo ( string s );
};

Error 182: "TestTempMethods.C", line 45 # "int main()" cannot access
protected member "void X<int>::foo()".
y.foo ( );
^^^^^^^^^
Warning 652: "TestTempMethods.C", line 29 # Virtual function "void
X<int>::foo()" is hidden by "void

Y::foo(std::basic_string said:
)"; did you forget to override it?
class Y : public X < int >
^^^^^^^
Warning 652: "TestTempMethods.C", line 29 # Virtual function "void
X<int>::foo(int)" is hidden by "void

Y::foo(std::basic_string said:
)"; did you forget to override it?
class Y : public X < int >
^^^^^^^

Moving the using declaration order gives the following errors -

class Y : public X < int >
{
public:
protected:
virtual void foo ( string s );
using X::foo;
};

Error 182: "TestTempMethods.C", line 45 # "int main()" cannot access
protected member "void X<int>::foo()".
y.foo ( );

Moving the using declaration to public section gives the following
warnings -

class Y : public X < int >
{
public:
using X::foo;
protected:
virtual void foo ( string s );
};


Warning 652: "TestTempMethods.C", line 29 # Virtual function "void
X<int>::foo()" is hidden by "void

Y::foo(std::basic_string said:
)"; did you forget to override it?
class Y : public X < int >
^^^^^^^
Warning 652: "TestTempMethods.C", line 29 # Virtual function "void
X<int>::foo(int)" is hidden by "void

Y::foo(std::basic_string said:
)"; did you forget to override it?
class Y : public X < int >
^^^^^^^
 
V

Victor Bazarov

gg said:
I am facing some problems with following program. I am using aCC
version 03.27 on HP-UX11. The command line I use to compile is -

aCC -AA -I. TestTempMethods.C

Can anybody pls suggest how to resolve the warnings and errors.

#include <iostream>
using namespace std;

#include <string.h>

template < class T >
class X
{
public:
virtual void foo ( );
protected:
virtual void foo ( int );
virtual void foo ( string ) = 0;
};

template < class T >
void X < T > :: foo ( )
{
foo ( 1 );
foo ( "a" );
}

template < class T >
void X < T > :: foo ( int i )
{
cout << " int " << i << endl;
}

class Y : public X < int >
{
public:
protected:
virtual void foo ( string s );

This function _hides_ the rest of the functions inherited from X<int>.
Add:

public:
using X said:
};

void Y::foo ( string s )
{
cout << " string " << s << endl;
}

int main ( void )
{
Y y;
y.foo ( );
}

The above version gives the following errors.
[...]

V
 
G

gg

Thanx, the following worked -

class Y : public X < int >
{
protected:
virtual void foo ( string s );
public:
using X<int>::foo;
};
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,901
Latest member
Noble71S45

Latest Threads

Top