472,353 Members | 1,414 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,353 software developers and data experts.

"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::DoSomething()':
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::DoSomething(){
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 18215
"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::DoSomething()':
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::DoSomething(){
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::DoSomething()':
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::DoSomething(){
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 ARluNonSymPencil contains ARluNonSymMatrix<TYPE>* A and
ARluNonSymMatrix<TYPE>* B. And class ARluNonSymMatrix (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. ARluNonSymMatrix declares some specialisation of the
template ARluNonSymPencil 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. ARluNonSymMatrix declares some specialisation of the
template ARluNonSymPencil 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
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...
6
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...
3
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
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...
2
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...
37
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...
94
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...
5
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...
3
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...
1
by: Kemmylinns12 | last post by:
Blockchain technology has emerged as a transformative force in the business world, offering unprecedented opportunities for innovation and...
0
by: Naresh1 | last post by:
What is WebLogic Admin Training? WebLogic Admin Training is a specialized program designed to equip individuals with the skills and knowledge...
0
jalbright99669
by: jalbright99669 | last post by:
Am having a bit of a time with URL Rewrite. I need to incorporate http to https redirect with a reverse proxy. I have the URL Rewrite rules made...
0
by: antdb | last post by:
Ⅰ. Advantage of AntDB: hyper-convergence + streaming processing engine In the overall architecture, a new "hyper-convergence" concept was...
0
by: AndyPSV | last post by:
HOW CAN I CREATE AN AI with an .executable file that would suck all files in the folder and on my computerHOW CAN I CREATE AN AI with an .executable...
0
by: Arjunsri | last post by:
I have a Redshift database that I need to use as an import data source. I have configured the DSN connection using the server, port, database, and...
0
hi
by: WisdomUfot | last post by:
It's an interesting question you've got about how Gmail hides the HTTP referrer when a link in an email is clicked. While I don't have the specific...
0
by: Matthew3360 | last post by:
Hi, I have been trying to connect to a local host using php curl. But I am finding it hard to do this. I am doing the curl get request from my web...
0
by: Rahul1995seven | last post by:
Introduction: In the realm of programming languages, Python has emerged as a powerhouse. With its simplicity, versatility, and robustness, Python...

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.