473,408 Members | 1,700 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,408 software developers and data experts.

problem with template class and overloaded methods

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<char,std::char_traits<cha r>,std::allocator<char>
)". y.foo ( );
^^^^^^^^^
Warning 652: "TestTempMethods.C", line 29 # Virtual function "void
X<int>::foo()" is hidden by "void

Y::foo(std::basic_string<char,std::char_traits<cha r>,std::allocator<char>)"; 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<char,std::char_traits<cha r>,std::allocator<char>)"; 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<char,std::char_traits<cha r>,std::allocator<char>)"; 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<char,std::char_traits<cha r>,std::allocator<char>)"; 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<char,std::char_traits<cha r>,std::allocator<char>)"; 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<char,std::char_traits<cha r>,std::allocator<char>)"; did you forget to override it?

class Y : public X < int >
^^^^^^^

Aug 10 '05 #1
2 2010
gg wrote:
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>
You don't need <string.h>, you need <string>.

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<int>::foo;
};

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

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

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


V
Aug 10 '05 #2
gg
Thanx, the following worked -

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

Aug 10 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: keit6736 | last post by:
Hi, I'm using the Borland compiler and I've created two templated classes in which I've overloaded the ostream << operator. However, when I try and use the operator on objects of either class I...
7
by: Tim Clacy | last post by:
Is there such a thing as a Singleton template that actually saves programming effort? Is it possible to actually use a template to make an arbitrary class a singleton without having to: a)...
1
by: Dave Corby | last post by:
Hi all, I have an overloaded template function, and in one particular spot can't get the right version of it to be called. Everywhere else in the program the correct version is called. Here's...
13
by: kamaraj80 | last post by:
Hi I am using the std:: map as following. typedef struct _SeatRowCols { long nSeatRow; unsigned char ucSeatLetter; }SeatRowCols; typedef struct _NetData
7
by: T.A. | last post by:
Class hierarchy below demonstrates my problem: #include <vector> #include <boost/smart_ptr.hpp> class Fruit { public: virtual ~Fruit() = 0; };
9
by: Rob | last post by:
I want to do something like this: template <typename MyType> std::vector<MYTypeget(SomeClass c) { ...elided... } int main()
0
by: anto.anish | last post by:
Hi , Since, i did not want to write all instantiations in Source file of all template methods for various different datatypes that my client might use, Instead, i choose to write implementation...
0
by: anto.anish | last post by:
Hi , Since, i did not want to write instantiations in Source file of all template methods for various different datatypes that my client might use, i choose to write implementation of template...
1
by: anto.anish | last post by:
Hi , Since, i did not want to write explicit instantiations in Source file of all template methods for various different datatypes that my client might use, i choose to write implementation of...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.