Protected classes within classes

  • Thread starter Kevin Grigorenko
  • Start date
K

Kevin Grigorenko

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
 
V

Victor Bazarov

Kevin Grigorenko said:
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
 
K

Kevin Grigorenko

Victor Bazarov said:
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?
 
V

Victor Bazarov

Kevin Grigorenko said:
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
 
K

Kevin Grigorenko

Victor Bazarov said:
which VC++

Members of a class have access to that class implicitly.


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
 
P

Peter van Merkerk

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.
 
D

Dan W.

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top