namespace and inheritance issue

T

Tomas

Hi all,
I don't know if this is just a "bug" in VisualStudio 6 or if I've
missed something...
If I do like this:

namespace NS
{

class CA
{
int A;
public:
virtual void Func() { A = 0; }
};

}

class CB : public NS::CA
{
int B;
public:
virtual void Func() { B = 0; NS::CA::Func(); }
};

the compiler gives 'illegal call of non-static member function'-error
message but if i add:
using namespace NS;
and removes NS:: it compiles fine.

Anyone knows?

Thanks in advance
/ Tomas
 
P

Peter van Merkerk

Hi all,
I don't know if this is just a "bug" in VisualStudio 6 or if I've
missed something...
If I do like this:

namespace NS
{

class CA
{
int A;
public:
virtual void Func() { A = 0; }
};

}

class CB : public NS::CA
{
int B;
public:
virtual void Func() { B = 0; NS::CA::Func(); }
};

the compiler gives 'illegal call of non-static member function'-error
message but if i add:
using namespace NS;
and removes NS:: it compiles fine.

Anyone knows?

Your code compiles fine with the Comeau compiler
(http://www.comeaucomputing.com/tryitout/). I suspect it is an issue
with the MSVC 6 compiler (no surprise). If you change B::Func() to { B =
0; CA::Func(); } it compiles on both.
 
N

Nils Petter Vaskinn

the compiler gives 'illegal call of non-static member function'-error
message but if i add:
using namespace NS;
and removes NS:: it compiles fine.

g++ seems to think it's proper c++, no error, not even a warning (as does
my very quick visual examination) Time to check what language features
your copy of VC supports.

Output of my test:

$ cat test.cpp
namespace NS
{

class CA
{
int A;
public:
virtual void Func() { A = 0; }
};


}
class CB : public NS::CA
{
int B;
public:
virtual void Func() { B = 0; NS::CA::Func(); }
};


int main() {
return 0;
}
$ g++ -Wall -ansi -pedantic -pedantic-errors test.cpp
$ g++ --version
g++ (GCC) 3.2.2 20030222 (Red Hat Linux 3.2.2-5)


hth
 
J

jeffc

Nils Petter Vaskinn said:
g++ seems to think it's proper c++, no error, not even a warning (as does
my very quick visual examination) Time to check what language features
your copy of VC supports.

VC 6 is mostly conforming, with a few glitches.
 
W

WW

jeffc said:
VC 6 is mostly conforming, with a few glitches.

Like barely implemented templates support, completely screwed up function
template support (uses overloading rules where it should not with wrong name
mangling), completely wrong for loop scoping and quite a few other serious
glitches, which makes it very much non-conforming in its default mode. In
its conforming mode it is impossible to use the standard library. It was
pretty good when it was released, but today it is not really good as a
standard C++ compiler.
 

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,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top