On Wed, 8 Jun 2011, Jack Harvard wrote:
On 8 Jun 2011, at 19:09, Nilay Vaish wrote:
On Wed, 8 Jun 2011, Jack Harvard wrote:
When you declare your function private, you can't use instance.function() to
access it. Is it generating a compile time error?
On 8 Jun 2011, at 00:31, Nilay Vaish wrote:
Consider the following class declarations --
class A
{
public:
virtual void function() = 0;
};
class B : public A
{
private:
void function();
}
int main()
{
B b;
b.function();
}
Will this code compile correctly?
--
Nilay
I should say that my example program was not what I intended it to be. The main
function should look like --
int main()
{
B* b = new B();
A* a = b;
a->function();
return 0;
}
Now what would happen?
This compiles. However, if you do b->function(), you would get the same error
as your last example, due to the same reason.
It compiles and executes fine. What surprises me is that even though
function() is private for class B, still it gets invoked using the pointer
from class A. I was not aware of this before.
--
Nilay
_______________________________________________
gem5-dev mailing list
gem5-dev@m5sim.org
http://m5sim.org/mailman/listinfo/gem5-dev