473,699 Members | 2,680 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

"is protected within this context" error


I am getting this error if I try to compile the file demarcated below.
What I am missing here? I am using g++ (GCC) 3.3.5 (Debian 1:3.3.5-8).

{tp2}> g++ -ansi -g -Wall tp2.cc -o tp2
tp2.cc: In member function `void Other::DoSometh ing()':
tp2.cc:11: error: `int Base::iX' is protected
tp2.cc:29: error: within this context
// %< %< ----------------------------------- %< %<
#include <cstdio>
#include <iostream>

class Base{
public:
Base();

protected:
int iX;
};

Base::Base():iX (7){}

class Derived:public Base{};

class Other{
public:
Derived* D;
void DoSomething();
};

void Other::DoSometh ing(){
std::cout << D->iX;
}

int main(){}

// %< %< ----------------------------------- %< %<
Thanks,
->HS

--
Please remove the underscores ( the '_' symbols) from my email address
to obtain the correct one. Apologies, but the fudging is to remove spam.
Jul 23 '05 #1
8 19260
"H. S." <g_************ **@yahoo.com> wrote...

I am getting this error if I try to compile the file demarcated below.
What I am missing here? I am using g++ (GCC) 3.3.5 (Debian 1:3.3.5-8).

{tp2}> g++ -ansi -g -Wall tp2.cc -o tp2
tp2.cc: In member function `void Other::DoSometh ing()':
tp2.cc:11: error: `int Base::iX' is protected
tp2.cc:29: error: within this context
// %< %< ----------------------------------- %< %<
#include <cstdio>
#include <iostream>

class Base{
public:
Base();

protected:
int iX;
};

Base::Base():iX (7){}

class Derived:public Base{};

class Other{
public:
Derived* D;
void DoSomething();
};

void Other::DoSometh ing(){
std::cout << D->iX;
iX is not a public member of 'Derived', you cannot expect it to be
accessible in an unrelated function. Only public members of Derived
are allowed to be used (accessed) in non-members (or somebody else's
members).
}

int main(){}

// %< %< ----------------------------------- %< %<


V
Jul 23 '05 #2
Apparently, _Victor Bazarov_, on 23/03/05 23:35,typed:
"H. S." <g_************ **@yahoo.com> wrote...
I am getting this error if I try to compile the file demarcated below.
What I am missing here? I am using g++ (GCC) 3.3.5 (Debian 1:3.3.5-8).

{tp2}> g++ -ansi -g -Wall tp2.cc -o tp2
tp2.cc: In member function `void Other::DoSometh ing()':
tp2.cc:11: error: `int Base::iX' is protected
tp2.cc:29: error: within this context
// %< %< ----------------------------------- %< %<
#include <cstdio>
#include <iostream>

class Base{
public:
Base();

protected:
int iX;
};

Base::Base(): iX(7){}

class Derived:public Base{};

class Other{
public:
Derived* D;
void DoSomething();
};

void Other::DoSometh ing(){
std::cout << D->iX;

iX is not a public member of 'Derived', you cannot expect it to be
accessible in an unrelated function. Only public members of Derived
are allowed to be used (accessed) in non-members (or somebody else's
members).


I am actually trying to compile a set of numerical libraries (ARPACK++
to be precise). The library was written, IIRC, in or around 1997 in C++.
I have already removed quite a few compiler errors. But I am still
getting an error similar to the above. I went through the library's code
and gave the minimal example in my original post which reproduced the
compiler error.

So, presumably the method was allowed/valid when the library was
written. And obviously it has changed. Just for knowledge's sake, when
and why did that happen?

But more important, what change would you suggest I make to the library
to remove that error. I do not want to mess more than necessary with the
library's code.

Thanks a ton,
->HS
--
Please remove the underscores ( the '_' symbols) from my email address
to obtain the correct one. Apologies, but the fudging is to remove spam.
Jul 23 '05 #3
H. S. wrote:
[...]
So, presumably the method was allowed/valid when the library was
written.
There is no proof of that, of course. Besides, AFA my knowledge of C++
and its evolution goes, accessing protected members has *never* been
allowed from an unrelated function.
And obviously it has changed. Just for knowledge's sake, when
and why did that happen?
When? Probably when you changed something in the code. Why? How should
anybody know but you? Seriously, do you know what "protected" means and
what it is for? Then you should be able to conclude the same things as I
did.
But more important, what change would you suggest I make to the library
to remove that error. I do not want to mess more than necessary with the
library's code.


Without seeing (and trying to compile) the original (1997) code, there is
no way to say what's needed. FWIW it could be that the class from which
you're trying to access the protected member *used to be* in the hierarchy
and somehow got out. It *could* be that the member you're trying to get
to *used to be* public but now it's protected. Which one it is, what to
do about it, is impossible for us to conclude without seeing the real code
in its entirety and its original form (which supposedly compiled).

I assure you the language did not change *so* drastically in the past ten
years that some ten year old code would suddenly not compile due to *that*
obvious of an error.

Good luck and post again soon.

V
Jul 23 '05 #4
Apparently, _Victor Bazarov_, on 24/03/05 09:44,typed:
H. S. wrote:
[...]
So, presumably the method was allowed/valid when the library was written.

There is no proof of that, of course. Besides, AFA my knowledge of C++
and its evolution goes, accessing protected members has *never* been
allowed from an unrelated function.
> And obviously it has changed. Just for knowledge's sake, when

and why did that happen?

When? Probably when you changed something in the code. Why? How should
anybody know but you? Seriously, do you know what "protected" means and
what it is for? Then you should be able to conclude the same things as I
did.


I am no C++ guru, but otherwise yes, I do know what protected means and
how to use it. And I did see the problem once I saw the compiler error
and looked at the library's source code. But again, it is not my source
code, I am only trying to compile it and have had to modiy it a bit.
But more important, what change would you suggest I make to the
library to remove that error. I do not want to mess more than
necessary with the library's code.

Without seeing (and trying to compile) the original (1997) code, there is
no way to say what's needed. FWIW it could be that the class from which


Well, for completeness' sake (and for any brave soul who might wanna try
this out), the original source code can be found here:
http://www.caam.rice.edu/software/ARPACK/arpack++.html

The problem is at line 274 of include/arlnspen.h:
if ((A->n != B->n)||(A->m != B->m)) {

Here, the class contains A and B, pointers to another derived class, and
is trying to access the "n" and "m" members of the base class of the
drived class.

The code to see this is fairly simple:
class ARluNonSymPenci l contains ARluNonSymMatri x<TYPE>* A and
ARluNonSymMatri x<TYPE>* B. And class ARluNonSymMatri x (defined in
arlnsmat.h) is derived from ARMatrix<TYPE> (defined in armat.h) which
has "m" and "n" as ints and are protected.

Note: You also need SuperLU package to compile ARPACK++. Found here:
http://crd.lbl.gov/~xiaoye/SuperLU/
you're trying to access the protected member *used to be* in the hierarchy
and somehow got out. It *could* be that the member you're trying to get
to *used to be* public but now it's protected. Which one it is, what t
do about it, is impossible for us to conclude without seeing the real code
in its entirety and its original form (which supposedly compiled).
See above. I am quite sure it originally compiled. The numerical library
seems to be quite popular.

I assure you the language did not change *so* drastically in the past ten
years that some ten year old code would suddenly not compile due to *that*
obvious of an error.
It would be nice if this indeed is the case. It would make my work a lot
easier. I could then get back to my real research work instead of trying
to compile this library.

Good luck and post again soon.


Thanks,
->HS

--
Please remove the underscores ( the '_' symbols) from my email address
to obtain the correct one. Apologies, but the fudging is to remove spam.
Jul 23 '05 #5
"H. S." wrote:


Well, for completeness' sake (and for any brave soul who might wanna try
this out), the original source code can be found here:
http://www.caam.rice.edu/software/ARPACK/arpack++.html


There is also an email address of the original author.
Contact him and tell him about the problem.

--
Karl Heinz Buchegger
kb******@gascad .at
Jul 23 '05 #6
Apparently, _Karl Heinz Buchegger_, on 24/03/05 10:54,typed:
"H. S." wrote:

Well, for completeness' sake (and for any brave soul who might wanna try
this out), the original source code can be found here:
http://www.caam.rice.edu/software/ARPACK/arpack++.html

There is also an email address of the original author.
Contact him and tell him about the problem.


I already did. It has been a couple of days and I am still waiting for
his response.

->HS

--
Please remove the underscores ( the '_' symbols) from my email address
to obtain the correct one. Apologies, but the fudging is to remove spam.
Jul 23 '05 #7
H. S. wrote:
Apparently, _Victor Bazarov_, on 24/03/05 09:44,typed:
[...]
Without seeing (and trying to compile) the original (1997) code, there is
no way to say what's needed. FWIW it could be that the class from which

Well, for completeness' sake (and for any brave soul who might wanna try
this out), the original source code can be found here:
http://www.caam.rice.edu/software/ARPACK/arpack++.html

The problem is at line 274 of include/arlnspen.h:
if ((A->n != B->n)||(A->m != B->m)) {


To pick a nit, there is no such statement on the line 274 of
'include/srlnspen.h' in the package I just downloaded. It's on
line 674. :-)
[...]


The cause of the trouble is potentially the way 'friend' declaration
is processed. ARluNonSymMatri x declares some specialisation of the
template ARluNonSymPenci l as friends. That _should_ give some of the
xxxPencil member functions (but only the ones specialised the same
way) permission to access any members of xxxMatrix. You have to make
sure that you use the proper specialisation. Only <df,df> and are
declared friends, along with <arcomplex<df >, df> where df is either
double or float. Could it be you're specialising your xxxPencil with
something other than double or float?

V
Jul 23 '05 #8
Apparently, _Victor Bazarov_, on 24/03/05 12:07,typed:
H. S. wrote:

<SNIP>
The problem is at line 274 of include/arlnspen.h:
if ((A->n != B->n)||(A->m != B->m)) {

To pick a nit, there is no such statement on the line 274 of
'include/srlnspen.h' in the package I just downloaded. It's on
line 674. :-)


Yes, it is 674. Sorry about that typo.

[...]

The cause of the trouble is potentially the way 'friend' declaration
is processed. ARluNonSymMatri x declares some specialisation of the
template ARluNonSymPenci l as friends. That _should_ give some of the
xxxPencil member functions (but only the ones specialised the same
way) permission to access any members of xxxMatrix. You have to make
sure that you use the proper specialisation. Only <df,df> and are
declared friends, along with <arcomplex<df >, df> where df is either
double or float. Could it be you're specialising your xxxPencil with
something other than double or float?

V


Let me have a more careful look at this before I report further. Thanks
for this explanation.
->HS

--
Please remove the underscores ( the '_' symbols) from my email address
to obtain the correct one. Apologies, but the fudging is to remove spam.
Jul 23 '05 #9

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

Similar topics

8
3372
by: TTroy | last post by:
I have a few questions about "scope" and "visibility," which seem like two different things. To me "visibility" of the name of a function or object is the actual code that can use it in an actual program. To me "scope" of the name of a function or object are the general rules for the areas of a program that can through a declaration, have "visibility."
6
6604
by: Dan | last post by:
I wish to replace all the occurrances of " with &quot; within a string. I have tried using myString.Replace("\"", "&quot;"), but this does not work Any suggestions will be greatly appreciated Thanks
3
6715
by: Jordan Taylor | last post by:
I am confused about protected member functions and objects. Is there any particular advantage of declaring members protected?
4
1822
by: Tina | last post by:
This is an issue regarding what exactly is accomplished by using "Protected" when defining a variable. It seems it does much more than just applying Protected status to a variable. I have an ascx control named HeadingBar. I have dragged it onto an aspx page. If I use the following statement..... Dim HeadingBar1 as HeadingBar
2
9916
by: Jeff | last post by:
hey asp.net 2.0 (C'#) In the code behind file I have this method: public String AddBR(Object param) { String text = (String) param; return text; }
37
3950
by: jht5945 | last post by:
For example I wrote a function: function Func() { // do something } we can call it like: var obj = new Func(); // call it as a constructor or var result = Func(); // call it as a function
94
30309
by: Samuel R. Neff | last post by:
When is it appropriate to use "volatile" keyword? The docs simply state: " The volatile modifier is usually used for a field that is accessed by multiple threads without using the lock Statement (C# Reference) statement to serialize access. " But when is it better to use "volatile" instead of "lock" ?
5
25203
patjones
by: patjones | last post by:
Hi: I've got a backend database, with several tables linked together via one-to-many relationships, and a front end database that links to those tables. The problem is, when I attempt to look at the relationships from the front end, I get '' is not a valid name. Make sure that it does not include invalid characters or punctuation and that it is not too long. According to the help window, this is Error 3125. Any ideas? Thank you ......
3
4293
by: eBob.com | last post by:
I'm getting this error on this statement ... Dim TA_rect As Rectangle = CType(Me.ClientRectangle.memberwiseclone(), Rectangle) "Me" inherits from UserControl. I'm not an OOD guru but maybe I sort of understand the problem. If so, this is not my fault, right? Since I can access ClientRectangle I don't see why I can't clone it. Is there anything easier/better than typing out all of
0
8615
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
9033
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8911
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8882
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7748
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...
0
5872
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
4375
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
3057
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
3
2009
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 can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.