By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,413 Members | 999 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,413 IT Pros & Developers. It's quick & easy.

Protected classes within classes

P: n/a
Hello,

I've been working on a little side project of mine in Visual Studio.NET for
about the last month. Recently, I wanted a friend of mine to help me out
with a problem and so I sent him my files and he tried to compile my project
in Visual C++ 6. A slew of random warnings and errors appeared which I
managed to solve very easily, but then I got an error that I suddenly could
not get access to a protected class within a class from that classes' member
functions. So, here is the basic layout:

class BasicRegex
{
protected:
class RegexNode
{
public:
std::vector< RegexNode *>::reference addNode();
...
};
public:
...
};

Then I had a member function in RegexNode called addNode which essentially
looked like this in my implementation file:

std::vector<BasicRegex::RegexNode *>::reference
BasicRegex::RegexNode::addNode()
{
children_.push_back(new BasicRegex::RegexNode);
return children_.back();
}

And MSVC++ 6 couldn't handle the line children_.push_back(new
BasicRegex::RegexNode); It was saying that I didn't have access to the
protected class RegexNode for some reason.

What is going on here? Have I created something that is non-standard, but
that .NET somehow accepts? Or is .NET correct, and MSVC++ 6 incorrect in
handling the nested class? What does the standard say about this situation?

Thank you,
Kevin Grigorenko
Jul 22 '05 #1
Share this Question
Share on Google+
6 Replies


P: n/a
"Kevin Grigorenko" <kz****@psu.edu> wrote...
Hello,

I've been working on a little side project of mine in Visual Studio.NET for about the last month. Recently, I wanted a friend of mine to help me out
with a problem and so I sent him my files and he tried to compile my project in Visual C++ 6. A slew of random warnings and errors appeared which I
managed to solve very easily, but then I got an error that I suddenly could not get access to a protected class within a class from that classes' member functions. So, here is the basic layout:

class BasicRegex
{
protected:
class RegexNode
{
public:
std::vector< RegexNode *>::reference addNode();
...
};
public:
...
};

Then I had a member function in RegexNode called addNode which essentially
looked like this in my implementation file:

std::vector<BasicRegex::RegexNode *>::reference
BasicRegex::RegexNode::addNode()
{
children_.push_back(new BasicRegex::RegexNode);
return children_.back();
}

And MSVC++ 6 couldn't handle the line children_.push_back(new
BasicRegex::RegexNode); It was saying that I didn't have access to the
protected class RegexNode for some reason.

What is going on here? Have I created something that is non-standard, but
that .NET somehow accepts? Or is .NET correct, and MSVC++ 6 incorrect in
handling the nested class? What does the standard say about this

situation?

My guess is that VC++ v 6 is so bad that you would do world a favour
if you switch your friend to a different compiler.

Victor
Jul 22 '05 #2

P: n/a
"Victor Bazarov" <v.********@comAcast.net> wrote in message
news:ExLzb.427632$Fm2.428775@attbi_s04...
"Kevin Grigorenko" <kz****@psu.edu> wrote...
Hello,

I've been working on a little side project of mine in Visual Studio.NET

for
about the last month. Recently, I wanted a friend of mine to help me out with a problem and so I sent him my files and he tried to compile my

project
in Visual C++ 6. A slew of random warnings and errors appeared which I
managed to solve very easily, but then I got an error that I suddenly

could
not get access to a protected class within a class from that classes'

member
functions. So, here is the basic layout:

class BasicRegex
{
protected:
class RegexNode
{
public:
std::vector< RegexNode *>::reference addNode();
...
};
public:
...
};

Then I had a member function in RegexNode called addNode which essentially looked like this in my implementation file:

std::vector<BasicRegex::RegexNode *>::reference
BasicRegex::RegexNode::addNode()
{
children_.push_back(new BasicRegex::RegexNode);
return children_.back();
}

And MSVC++ 6 couldn't handle the line children_.push_back(new
BasicRegex::RegexNode); It was saying that I didn't have access to the
protected class RegexNode for some reason.

What is going on here? Have I created something that is non-standard, but that .NET somehow accepts? Or is .NET correct, and MSVC++ 6 incorrect in handling the nested class? What does the standard say about this

situation?

My guess is that VC++ v 6 is so bad that you would do world a favour
if you switch your friend to a different compiler.

Victor


Hahaha, I agree, but in the long run I wouldn't mind this working on VC++ 6
and I really would rather not make the RegexNode class public. So the
question of what the standard says about this is still outstanding? Are you
implying that this is allowed and that VC++ 6 just can't handle it? And if
so, what options do I have, if any, without taking the class out of the
BasicRegex class and making it public?
Jul 22 '05 #3

P: n/a
"Kevin Grigorenko" <kz****@psu.edu> wrote...
"Victor Bazarov" <v.********@comAcast.net> wrote in message
news:ExLzb.427632$Fm2.428775@attbi_s04...
"Kevin Grigorenko" <kz****@psu.edu> wrote...
Hello,

I've been working on a little side project of mine in Visual Studio.NET
for
about the last month. Recently, I wanted a friend of mine to help me out with a problem and so I sent him my files and he tried to compile my project
in Visual C++ 6. A slew of random warnings and errors appeared which
I managed to solve very easily, but then I got an error that I suddenly

could
not get access to a protected class within a class from that classes'

member
functions. So, here is the basic layout:

class BasicRegex
{
protected:
class RegexNode
{
public:
std::vector< RegexNode *>::reference addNode();
...
};
public:
...
};

Then I had a member function in RegexNode called addNode which

essentially looked like this in my implementation file:

std::vector<BasicRegex::RegexNode *>::reference
BasicRegex::RegexNode::addNode()
{
children_.push_back(new BasicRegex::RegexNode);
return children_.back();
}

And MSVC++ 6 couldn't handle the line children_.push_back(new
BasicRegex::RegexNode); It was saying that I didn't have access to the protected class RegexNode for some reason.

What is going on here? Have I created something that is non-standard, but that .NET somehow accepts? Or is .NET correct, and MSVC++ 6 incorrect in handling the nested class? What does the standard say about this

situation?

My guess is that VC++ v 6 is so bad that you would do world a favour
if you switch your friend to a different compiler.

Victor


Hahaha, I agree, but in the long run I wouldn't mind this working on VC++

6 and I really would rather not make the RegexNode class public. So the
question of what the standard says about this is still outstanding?
Members of a class have access to that class implicitly.
Are you
implying that this is allowed and that VC++ 6 just can't handle it?
Yes.
And if
so, what options do I have, if any, without taking the class out of the
BasicRegex class and making it public?


You better ask in microsoft.public.vc.language. I am afraid, however,
that even there you'll be encouraged to update your compiler...

Victor
Jul 22 '05 #4

P: n/a
"Victor Bazarov" <v.********@comAcast.net> wrote in message
news:fXMzb.303527$275.1043028@attbi_s53...
"Kevin Grigorenko" <kz****@psu.edu> wrote...
"Victor Bazarov" <v.********@comAcast.net> wrote in message
news:ExLzb.427632$Fm2.428775@attbi_s04...
"Kevin Grigorenko" <kz****@psu.edu> wrote...
> Hello,
>
> I've been working on a little side project of mine in Visual Studio.NET for
> about the last month. Recently, I wanted a friend of mine to help me
out
> with a problem and so I sent him my files and he tried to compile my
project
> in Visual C++ 6. A slew of random warnings and errors appeared
which
I > managed to solve very easily, but then I got an error that I
suddenly could
> not get access to a protected class within a class from that classes' member
> functions. So, here is the basic layout:
>
> class BasicRegex
> {
> protected:
> class RegexNode
> {
> public:
> std::vector< RegexNode *>::reference addNode();
> ...
> };
> public:
> ...
> };
>
> Then I had a member function in RegexNode called addNode which essentially
> looked like this in my implementation file:
>
> std::vector<BasicRegex::RegexNode *>::reference
> BasicRegex::RegexNode::addNode()
> {
> children_.push_back(new BasicRegex::RegexNode);
> return children_.back();
> }
>
> And MSVC++ 6 couldn't handle the line children_.push_back(new
> BasicRegex::RegexNode); It was saying that I didn't have access to the > protected class RegexNode for some reason.
>
> What is going on here? Have I created something that is

non-standard, but
> that .NET somehow accepts? Or is .NET correct, and MSVC++ 6
incorrect in
> handling the nested class? What does the standard say about this
situation?

My guess is that VC++ v 6 is so bad that you would do world a favour
if you switch your friend to a different compiler.

Victor


Hahaha, I agree, but in the long run I wouldn't mind this working on

VC++ 6
and I really would rather not make the RegexNode class public. So the
question of what the standard says about this is still outstanding?


Members of a class have access to that class implicitly.
Are you
implying that this is allowed and that VC++ 6 just can't handle it?


Yes.
And if
so, what options do I have, if any, without taking the class out of the
BasicRegex class and making it public?


You better ask in microsoft.public.vc.language. I am afraid, however,
that even there you'll be encouraged to update your compiler...

Victor


Thanks! I appreciate it. I didn't think MSVC++ 6 was that bad. .NET seems
to be quite an improvement then. Oh well, I guess I will just suggest
anyone trying to compile my program to either update their compiler :) or
move the class outside the outer class. Do you think I'll have these kinds
of problems with GCC from your experience (if you have any experience with
GCC)?

Thanks for your time,
Kevin Grigorenko
Jul 22 '05 #5

P: n/a
> Thanks! I appreciate it. I didn't think MSVC++ 6 was that bad.

It is that bad.
.NET seems
to be quite an improvement then.
It is.
Oh well, I guess I will just suggest
anyone trying to compile my program to either update their compiler :) or
move the class outside the outer class.
Sometimes there is a good reason stick with an older compiler. Even though
MSVC 6 is old and very far from being compliant with the C++ standard, it is
still widely used. On the other hand there is something to say for
stimulating people to use a compliant compiler, otherwise we will be stuck
with MSVC6 forever. So the desision is up to you :-)
Do you think I'll have these kinds
of problems with GCC from your experience (if you have any experience with
GCC)?


If you use a recent GCC version (3.X) I would expect not; it is a very good
compiler.

--
Peter van Merkerk
peter.van.merkerk(at)dse.nl
Jul 22 '05 #6

P: n/a
>
Thanks! I appreciate it. I didn't think MSVC++ 6 was that bad. .NET seems
to be quite an improvement then. Oh well, I guess I will just suggest
anyone trying to compile my program to either update their compiler :) or
move the class outside the outer class. Do you think I'll have these kinds
of problems with GCC from your experience (if you have any experience with
GCC)?

Thanks for your time,
Kevin Grigorenko


Just in case I ask, does your friend have Service Pack 5 installed,
for VC6? I used to have VC6 and it was useless until I got SP5
installed, then it was somewhat passable.
Jul 22 '05 #7

This discussion thread is closed

Replies have been disabled for this discussion.