473,394 Members | 1,845 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,394 software developers and data experts.

hack to make a member function final

Not that this serves any real purpose, but gcc allows me to do some hack
like this:

class hide_A {
public:
class A {
public:
virtual int final() { return 42; }
};

class A_finalize {
public:
virtual void final() {}
};
friend class B;
};

class B : public hide_A::A, private hide_A::A_finalize {
public:
void final() { } //error
};
You can't use A directly and have to access it through B. But you can't
override final() because it will have a conflicting return type no
matter what you do.

Is this valid standard C++? Anyone see any way to circumvent this or any
major problems (other than having no practical value)?

-Rajib
Aug 3 '08 #1
1 1668
Rajib wrote:
Not that this serves any real purpose, but gcc allows me to do some hack
like this:

class hide_A {
public:
class A {
public:
virtual int final() { return 42; }
};

class A_finalize {
public:
virtual void final() {}
};
friend class B;
};

class B : public hide_A::A, private hide_A::A_finalize {
public:
void final() { } //error
};
You can't use A directly and have to access it through B. But you can't
override final() because it will have a conflicting return type no
matter what you do.
This is not true, class A is a public class in hide_A. Also, changing the
access to private results in an error.
Is this valid standard C++? Anyone see any way to circumvent this or any
major problems (other than having no practical value)?
You can get around the restriction by introducing another class, C, and
having B only inherit from the A_finalize class:

class B : private hide_A::A_finalize
{
public:
void final(){}
};

class C : public B, public hide_A::A
{};

And now you just have client code use class C. Not sure if this is what you
were looking for, though.

-- B

Aug 3 '08 #2

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

Similar topics

7
by: christopher diggins | last post by:
Hi everyone, I have the following code (greatly simplified to demonstrate issue) : #include <iostream> class CBaseFuBar { public: virtual void Fu() { std::cout << "base"; }; };
31
by: Ben | last post by:
For many times, I've found myself changing my member variables from const back to non-const. No matter how good the original objective was, there was always at least one reason not to use const...
0
by: Chris F Clark | last post by:
In our C++ project we have some internal bug reporting macros that we use to get useful information when the program does something unexpected. Essentially at the point of the error, we invoke an...
3
by: Krish | last post by:
Hi There, I am having problem when I compile a code which I create to test a source file. The errors are : error C2144: syntax error : 'void' should be preceded by ';' error C2511: 'void...
1
by: Randy Yates | last post by:
If a member function uses no static local variables, then is only one "pure root" of that member function's code used by all instantiated objects or is its code duplicated for each instantiated...
0
by: Xah Lee | last post by:
In this article, i explain how the use of bit masks is a hack in many imperative languages. Often, a function will need to take many True/False parameters. For example, suppose i have a function...
6
by: Chris Thomasson | last post by:
I was wondering of the foo::m_fp_callback member will really have extern "C" linkage... simple code ____________________________ #include <cstdio>
1
by: Erik Jones | last post by:
So, I was just taking a look at doctest.py and saw this: Then running the module as a script will cause the examples in the docstrings to get executed and verified: python M.py This won't...
6
by: Charles A. Landemaine | last post by:
Hello, My GUI works fine in the following browsers: - IE6 - IE7 - Opera - Safari - Firefox - Seamonkey - Konqueror
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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...

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.