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

trying to make a class (ABase) non-derivable

please see the following lines of codes :

class ABase; // i want to make it non-derivable

class Super
{
private:
Super () {};
friend class ABase;
};

class ABase : virtual public Super
{
private:
int i;
public:
ABase () {}
void seti (int j) { i=j; }
int geti () { return i; }
};

void main()
{
ABase a;
a.seti(100);
cout<<endl<<a.geti()<<endl;
}

here if we try to derive a class from ABase ;
class BDer : public ABase
{
public:
BDer() {}
};

the compiler is giving an error "Super::Super' : cannot access private
member declared in class 'Super'".

But if we remove the "virtual" in class ABase : virtual public Super,
then we can derive from ABase. How the keyword "virtual" making ABase
non-derivable??? Is there any workaround for this problem???

I hope the problem is clear to you.

Thanks,
Amit Kumar.

Jul 23 '05 #1
2 1835
Amit wrote:
please see the following lines of codes :

class ABase; // i want to make it non-derivable
[..]


This is a FAQ. Please look in the archives.
Jul 23 '05 #2
> please see the following lines of codes :
class ABase; // i want to make it non-derivable
See FAQ[23.8]
class Super
{
private:
Super () {};
friend class ABase;

}; class ABase : virtual public Super
{
private:
int i;
public:
ABase () {}
}; void main()
See FAQ[29.3]
{
ABase a;
a.seti(100);
cout<<endl<<a.geti()<<endl;
} here if we try to derive a class from ABase ;
class BDer : public ABase
{
public:
BDer() {}
}; the compiler is giving an error "Super::Super' : cannot access private
member declared in class 'Super'".
But if we remove the "virtual" in class ABase : virtual public Super,
then we can derive from ABase. How the keyword "virtual" making ABase
non-derivable???
See FAQ[25.12]
Is there any workaround for this problem???
See FAQ[23.8] again.
I hope the problem is clear to you.


Yes. RTFM.

Jonathan

Jul 23 '05 #3

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

Similar topics

5
by: apchar | last post by:
I am trying to use php as a kind of servlet to act as a middle man between a java applet and mysql. I know java has jdbc but it's flakey and painful. php access to mysql is much nicer. So I have:...
5
by: winbatch | last post by:
Hi, I'm trying to write code such that my class can be used like so: To accomplish this, I'm trying to overload the + operator of my class to return a string. I am able to do this, but when I...
1
by: David | last post by:
Hello, Is there a way to automatically have a member variable in a derived class recast within that class. In other words, something like this: class ABase { protected: BBase *m_something;...
13
by: cj | last post by:
Stephany Young provided me with the following code to count threads created by my program. Public Class MyThreadCount Private Shared m_lock As New Object Private Shared m_threadcount As Int32...
6
by: scottyman | last post by:
I can't make this script work properly. I've gone as far as I can with it and the rest is out of my ability. I can do some html editing but I'm lost in the Java world. The script at the bottom of...
7
by: for.fun | last post by:
Hi everybody, I have the following problem : B class need A::MyEnum type and A class need B::MyEnum type. In both case, the class type is incomplete so it is obvious that the ::MyEnum can not...
1
by: shady | last post by:
I am trying to create a a three column page with fixed size left and right columns and sretching middle one that uses left and right margins to give space to the left and right columns. It worked...
10
by: blangela | last post by:
If I pass a base class object by reference (likely does not make a difference here that it is passed by reference) as a parameter to a derived class member function, the member function is not...
11
by: Hendrik Schober | last post by:
Hi, I'm having two overloaded function templates, #include <iterator> template< typename T > void test( T /*a1*/, T /*a2*/ ) {} template< typename Iter >
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...

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.