Unknown use of protected member functions.

Hi.
This is my first post to the list.

I'm working with a C++ framework that has something like this:

class A {
protected:
virtual void init();
virtual void run();

// rest of the class
...
}

class B : public A {
public:
A::init;
A::run;

// rest of the class
...
}

I have never seem the use of A::init; and A::run; in that way before.
What are they supposed to be?
How do they afect to class B?
What do you think is the purpose of them?

Tom
1
2
A::init;
A::run;


1
2
virtual void init();
virtual void run();


1
2
3
4
5
6
7
8
9
virtual B::init()
{
   A::init();
}
virtual B::run()
{
   A::run();
}
1
2
A::init;
A::run;


1
2
virtual void init();
virtual void run();


1
2
3
4
5
6
7
8
9
virtual B::init()
{
   A::init();
}
virtual B::run()
{
   A::run();
}
So here is a "explained" answer from comp.lang.c++:

It means that init and run are now in the public interface of B. Without
them they would be inaccessible to the outside world (unrelated classes).

int main()
{
A a;
a.init(); // Inaccessible
B b;
b.init(); // Kosher

}

So B has basically modified what it exposes to the outside world.
I'm not sure about this, I think you're supposed to include the using keyword like this:
1
2
using A::init;
using A::run;


..or it may have a slightly different meaning.
ropez wrote:
> I'm not sure about this, I think you're supposed to include the
> using keyword like this:
1
2
using A::init;
using A::run;

>
> ..or it may have a slightly different meaning.

I have always seen it like that too. I wonder if someone else can comment on this that is a bit more knowledgeable. The only thing I can think of is the idea that the code was created before C++ had a 'using' keyword...
Last edited on
closed account (z05DSL3A)
Section 11.3 Access declarations, paragraph 1 of ISO/IEC 14882:1998 states:
The access of a member of a base class can be changed in the derived class by mentioning its qualified-id in the derived class declaration. Such mention is called an access declaration. The effect of an access declaration ‘qualified-id;’ is defined to be equivalent to the declaration ‘using qualified-id;’. *

*Access declarations are deprecated; member using-declarations (7.3.3) provide a better means of doing the same thing.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
class A {
protected:
	virtual void init(){};
	virtual void run(){};
};

class B : public A {
public:
	A::init;  //Access declarations (98std 11.3)
	A::run;   //Access declarations (98std 11.3)
};

class C : public A
{
public:
	using A::init; //Using-declaration used as member-declaration (98std 7.3.3.4) 
	using A::run;  //Using-declaration used as member-declaration (98sts 7.3.3.4)
};

Last edited on
Thanks for that, Grey Wolf. It was nice to see things from the source (whether it is part of a draft or an official copy of the standard).
Topic archived. No new replies allowed.