paul@slhisc.uucp (Paul Tam) (11/27/90)
I have a question about Zortech C++ compiler 2.0. I am new to
c++ and am using Zortech c++ compiler to learn the language.
However I came across some interesting result that to my understanding
shouldn't have happened.
I have a little sample program which has defined one parent_class and
a derived_class from the parent_class. The derived_class is declared
to have private inheritance from the parent class. In theory any
member functions of the parent_class are not visible to derived_class's
objects. (If I'm not mistaken).
However the interesting result I got is in my main, I can call the
member functions of parent_class from derived_class object d1.
Are these kind of errors supposed to be picked up by the compiler ?
If the answer is yes, How come Zortech's c++ compiler failed to
pick it up. Is this a bug?
If this is a bug, it is a very serious one. Should I think about
upgrade to Zortech's c++ compiler v2.1 ?
Here are the source of my test program:
-------------------------------------------------------------------
#include <stdio.h>
class parent_class
{
private:
int private1, private2;
public:
parent_class (int p1, int p2)
{
private1 = p1;
private2 = p2;
}
void assign (int p1, int p2)
{
private1 = p1;
private2 = p2;
}
int inc1 () { return ++private1; }
int inc2 () { return ++private2; }
void display ()
{
printf ("\nprivate1 = %d, private2 = %d", private1,
private2);
}
};
class derived_class1 : private parent_class
{
private:
int private3;
parent_class private4;
public:
derived_class1 (int p1, int p2, int p3, int p4, int p5)
: (p1, p2), private4 (p3, p4)
{
private3 = p5;
}
};
main ()
{
derived_class1 d1(17,18, 1, 2, -5);
d1.inc1 ();
d1.inc2 ();
d1.display ();
}
-------------------------------------------------------------------------
the result is
private1 = 18, private2 = 19
I'd appreciate any answers and thanks for any better solutions
Paul