Q: Derived classes and hidden functions

J

Jakob Bieling

Hi,

Please have a look at the following snippet:

class test_i
{
public:
virtual int myfunc () = 0;
};

template <class T>
class extra_class
{
public:
void test (int i) {}
};

template <class i, template <class> class e>
class base : public i,
public e <i>
{
};

class test_class : public base <test_i, extra_class>
{
public:
void test () {}
int myfunc ()
{
test (1);
}
};

The problem I have is, that 'test_class' actually contains the function
'test(int)' by the way it is deriving, but it gets hidden by the local
definition 'test ()'. I know I can use the 'using' keyword to unhide the
first 'test' function, but I do not know how that would look like. 'using
extra_class <test_i>::test;' does not work for me. I am using VC++ 7.1. Can
I achieve my goal at all?

Thanks in advance!
 
J

John Carson

Jakob Bieling said:
Hi,

Please have a look at the following snippet:

class test_i
{
public:
virtual int myfunc () = 0;
};

template <class T>
class extra_class
{
public:
void test (int i) {}
};

template <class i, template <class> class e>
class base : public i,
public e <i>
{
};

class test_class : public base <test_i, extra_class>
{
public:
void test () {}
int myfunc ()
{
test (1);
}
};

The problem I have is, that 'test_class' actually contains the
function 'test(int)' by the way it is deriving, but it gets hidden by
the local definition 'test ()'. I know I can use the 'using' keyword
to unhide the first 'test' function, but I do not know how that would
look like. 'using extra_class <test_i>::test;' does not work for me.
I am using VC++ 7.1. Can I achieve my goal at all?

'using extra_class <test_i>::test;' DOES work for me using VC++ 7.1. Are you
making the declaration at class scope or nested inside myfunc? It should be
at class scope. Incidentally, myfunc needs to return an int.
 
J

Jakob Bieling

John Carson said:
'using extra_class <test_i>::test;' DOES work for me using VC++ 7.1. Are you
making the declaration at class scope or nested inside myfunc? It should be
at class scope. Incidentally, myfunc needs to return an int.


Hm, funny thing, now it does work indeed. Guess I misspelled it last
time I tried. And yes for the returning of int, guess I stripped down too
much of my original code :)

Thanks for the hint!
 

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

No members online now.

Forum statistics

Threads
473,763
Messages
2,569,562
Members
45,038
Latest member
OrderProperKetocapsules

Latest Threads

Top