Q: Derived classes and hidden functions

Discussion in 'C++' started by Jakob Bieling, Jun 16, 2004.

  1. 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!
    --
    jb

    (replace y with x if you want to reply by e-mail)
     
    Jakob Bieling, Jun 16, 2004
    #1
    1. Advertising

  2. Jakob Bieling

    John Carson Guest

    Re: Derived classes and hidden functions

    "Jakob Bieling" <> wrote in message
    news:cap447$jev$00$-online.com
    > 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.


    --
    John Carson
    1. To reply to email address, remove donald
    2. Don't reply to email address (post here instead)
     
    John Carson, Jun 17, 2004
    #2
    1. Advertising

  3. Re: Derived classes and hidden functions

    "John Carson" <> wrote in message
    news:40d12bef$...
    > "Jakob Bieling" <> wrote in message
    > news:cap447$jev$00$-online.com
    > > 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.



    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!
    --
    jb

    (replace y with x if you want to reply by e-mail)
     
    Jakob Bieling, Jun 17, 2004
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Colin Goudie
    Replies:
    6
    Views:
    477
    Victor Bazarov
    Jan 26, 2004
  2. Manuel
    Replies:
    8
    Views:
    644
    Manuel
    Jan 5, 2006
  3. Replies:
    6
    Views:
    381
  4. Replies:
    1
    Views:
    397
    myork
    May 23, 2007
  5. Replies:
    1
    Views:
    390
    Victor Bazarov
    May 23, 2007
Loading...

Share This Page