473,785 Members | 2,612 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Can Derived class static member access protected member from base class?

Can Derived class static member access protected member from base class?

class Base {
protected:
void setvariable(int );
};

class Derived : Base {
public:
static std::auto_ptr<B ase> out(new Derived());
out->setvariable(3) ; // my compiler gives is not accessible error here!
return out;
};
Jul 22 '05 #1
4 2995
Siemel Naran wrote:
Can Derived class static member access protected member from base class?


No. Same reasons why it doesn't for a non-static member.
(I'm assuming that all that stuff after public: in Derived
is really in a member function).
Jul 22 '05 #2
Ron Natalie wrote:
Siemel Naran wrote:
Can Derived class static member access protected member from base class?


No. Same reasons why it doesn't for a non-static member.


Um, isn't the very definition of a protected member that it can
be accessed by classes derived from the base?

I'm thinking the code may well be as seen in OP... :-)
Jul 22 '05 #3
"Micah Cowan" <mi***@cowan.na me> wrote...
Um, isn't the very definition of a protected member that it can be
accessed by classes derived from the base?


It's a bit more complicated than that. The issue of protected
access and how it sometimes "doesn't work" has been discussed so
many times here and in c.l.c++.moderat ed that it doesn't really
make sense to begin again.
Jul 22 '05 #4
Victor Bazarov wrote:
"Micah Cowan" <mi***@cowan.na me> wrote...
Um, isn't the very definition of a protected member that it can be
accessed by classes derived from the base?

It's a bit more complicated than that. The issue of protected
access and how it sometimes "doesn't work" has been discussed so
many times here and in c.l.c++.moderat ed that it doesn't really
make sense to begin again.


Mm, never mind, I've spotted my thinko now.
Jul 22 '05 #5

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

Similar topics

3
11832
by: Kirk Marple | last post by:
Just want to see if this is 'by design' or a bug... I have a common List<T> defined in a base class, and the base class has a static property to expose this list. I wanted the derived class to add items to this list, but have the base class hold the data and expose the property. Problem is, however, that the derived class' static constructor doesn't get called when DerivedClass.MyList is accessed, so the list has no members. If
3
3850
by: Jasleen | last post by:
I want to access the protected member hresult of the Exception class, so I derived my own class from ApplicationException and SystemException. public class LoggedException : SystemException { public LoggedException() : base() { } public LoggedException(String message) : base (message)
14
24617
by: Edward Diener | last post by:
In C++ one can change the access level in a derived class by the "using" keyword. So, for instance, a public method in a base class can be made private in a derived class. Is there any way of doing this in C# ?
3
2057
by: keith.thornhill | last post by:
hey all, got a problem here using Visual basic .net 2005 i have two pairs of base/derived classes. lets call them Base/Derived and BaseStruct/DerivedStruct. i want to be able to instantiate a DerivedStruct in my Derived class, but have the instance of it be accessible from both the Base class (as BaseStruct) and Derived class (as DerivedStruct) this is the kind of code i'm looking to be able to use
15
3853
by: Bob Johnson | last post by:
I have a base class that must have a member variable populated by, and only by, derived classes. It appears that if I declare the variable as "internal protected" then the base class *can* populate the variable, but the population is not *required* by the derived class (which must be the case). What would meet the requirements is if I create an abstract method in the base class that populates the member variable. In this case the...
15
3086
by: =?Utf-8?B?R2Vvcmdl?= | last post by:
Hello everyone, I met with a strange issue that derived class function can not access base class's protected member. Do you know why? Here is the error message and code. error C2248: 'base::~base' : cannot access protected member declared in
4
2954
by: softwaredoug | last post by:
Here is some test code I've been attempting to compile (Visual Studio 2003) test.h: class Base { protected: Base() {} public:
3
1979
by: Edan | last post by:
I have a base class with protected members (`Base`). The function `MakeBase()` is a member function of another class, that returns a `Base` object initialized with private members of this class. Now the thing is, I want to extend the functionality of `Base` class. I do that by inheriting `Base` class by `Derived`, but then I can't use `MakeBase()` function. It all makes sense to me, but I don't seem to find an appropriate solution. Since I...
10
4118
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 allowed to access the protected data members of the base object. This surprises me. Can someone explain why this is? I suspect there is a good reason and I am just having a slow day to not come up with it myself. Bob
0
9645
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9481
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10336
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8978
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7502
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6741
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5383
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4054
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3655
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.