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