473,508 Members | 2,128 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Hiding rule and pure virtuals

Hi everyone,
following situation:

class A
{
void m(T value) =0;
}

class B : A
{
void m(TA value);
void m(TB value);
}

class T
{
}

class TA : T
{
}

class TB : T
{
}

The original methode A::m(T) is not overriden, just hidden by B::m. Is
B an "abstract" class and have to overwrite m(T) specificly? Can a
methode call like this be resolved like expected according to the
C++Spec:
B b;
TA ta;
b.m(ta);
Thanks in advance,
Thomas Kowalski

Aug 24 '06 #1
3 3611
I am not sure whether you can do that. I am using gcc 4.1.0 here is
what I compiled and the error I got.

#include <iostream>

using namespace std;

class T;
class TA;
class TB;

class A
{
virtual void m ( T value) = 0;

};

class B : A
{
public:
void m ( TA value);
void m ( TB value);
};

class T
{

};

class TA : T
{

};

class TB : T
{

};

int main()
{
B obj;
TA obj_ta;

obj.m ( obj_ta);
}

class.cpp: In function 'int main()':
class.cpp:39: error: cannot declare variable 'obj' to be of abstract
type 'B'
class.cpp:16: note: because the following virtual functions are pure
within 'B':
class.cpp:11: note: virtual void A::m(T)

Thomas Kowalski wrote:
Hi everyone,
following situation:

class A
{
void m(T value) =0;
}

class B : A
{
void m(TA value);
void m(TB value);
}

class T
{
}

class TA : T
{
}

class TB : T
{
}

The original methode A::m(T) is not overriden, just hidden by B::m. Is
B an "abstract" class and have to overwrite m(T) specificly? Can a
methode call like this be resolved like expected according to the
C++Spec:
B b;
TA ta;
b.m(ta);
Thanks in advance,
Thomas Kowalski
Aug 24 '06 #2
Thomas Kowalski wrote:
Hi everyone,
following situation:

class A
{
void m(T value) =0;
}
I guess you probably want the following:

class T;

class A
{
public:
virtual void m(T value) = 0;
};

Note that:
1. Type T is declared before it is used.
2. Member function m() is now a public member.
3. m() is also made virtual. Otherwise the "=0" is just an utter error.
4. The class definition ends with a semicolon.
>
class B : A
{
void m(TA value);
void m(TB value);
}
Again, I guess you want the following:

class TA;
class TB;

class B: public A
{
public:
void m(TA value);
void m(TB value);
};
>
class T
{
}

class TA : T
{
}

class TB : T
{
}
Reminder: Both TA and TB privately inherits from T, and all three
classes need semicolon to end with.
>
The original methode A::m(T) is not overriden, just hidden by B::m. Is
B an "abstract" class and have to overwrite m(T) specificly? Can a
methode call like this be resolved like expected according to the
C++Spec:
Class A is abstract, it declares a pure virtual member function. Unless
class B explicitly implements the pure virtual member function A::m, it
remains abstract.
B b;
TA ta;
b.m(ta);
Technically, if B is abstract then you can't instantiate an object of
type B, so never mind what happens to the object.

On the other hand if you make B non-abstract by supplying an
implementation of A::m in B, e.g.

class B: public A
{
public:
void m(T);
void m(TA);
void m(TB);
};

then overload resolution will guarantee the right overload gets invoked.
>

Thanks in advance,
Thomas Kowalski
Ben
Aug 24 '06 #3
as***********@gmail.com wrote:
I am not sure whether you can do that.

Please don't top-post. Your replies belong following or interspersed
with properly trimmed quotes. See the majority of other posts in the
newsgroup, or the group FAQ list:
<http://www.parashift.com/c++-faq-lite/how-to-post.html>
Brian (another one tops the post)
Aug 24 '06 #4

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

Similar topics

5
2763
by: Steven T. Hatton | last post by:
This is a question about coding styles. I've seen some cases where the programmer has redeclared the pure virtual functions from an interface class in the implementation derived from it. For...
10
7274
by: Martin Vorbrodt | last post by:
Example code in one of my books intrigues me: class B { public: B* Clone() const { B* p = DoClone(); assert(typeid(*p) == typeid(*this)); return p; }
7
3123
by: Edward Yang | last post by:
A few days ago I started a thread "I think C# is forcing us to write more (redundant) code" and got many replies (more than what I had expected). But after reading all the replies I think my...
17
3215
by: Riaan | last post by:
Hi Everybody, I created an abstract class containing all my pure virtual functions. I derived a new class from this and implemented all the functions needed. Every time I compile, I get the...
4
1668
by: Ole Nielsby | last post by:
I'm puzzed by this: /***code begin***/ class X {}; class Y : public X {}; class A { public: virtual void m(X x) {std::wcout << L"A\n";} }; class B : public A {
4
1707
by: Arne Schmitz | last post by:
If i have an abstract base class, that only contains pure virtual methods (and maybe some non-virtual methods), is a vtable still being generated, for the first derived class that implements those...
8
8337
by: mfabricius | last post by:
Hi, I am probably trying to do something really stupid. There is a class shape: class Shape { public: Shape();
2
1617
by: Mike -- Email Ignored | last post by:
Pure operator= thus: class A // abstract { virtual A& operator=(const A&); // has a purpose }; class B : public A // never...
162
10065
by: Sh4wn | last post by:
Hi, first, python is one of my fav languages, and i'll definitely keep developing with it. But, there's 1 one thing what I -really- miss: data hiding. I know member vars are private when you...
0
7225
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7123
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
7498
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...
1
5053
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...
0
4707
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3194
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3182
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
766
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
418
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.