CRTP question

Discussion in 'C++' started by fabioppp, Apr 15, 2005.

  1. fabioppp

    fabioppp Guest

    Is this piece of code correct?

    template<typename Child>
    struct Base
    {
    enum { derived_id = Child::id }; // <= wont compile!

    void invokeDispatch()
    {
    ((Child*) this)->invoke(); // <= this compile fine!
    }
    };

    struct Derived1 : public Base<Type1>
    {
    enum { id = 1 };

    void invoke()
    {

    }
    };

    Why the enum doesn't compile, while invokeDispatch seems to be fine?

    Thanks

    --
    Fabio.
     
    fabioppp, Apr 15, 2005
    #1
    1. Advertising

  2. fabioppp

    fabioppp Guest

    fabioppp wrote:
    >
    > struct Derived1 : public Base<Type1>
    > {
    > enum { id = 1 };
    >
    > void invoke()
    > {
    >
    > }
    > };



    Sorry... it's:

    struct Derived1 : public Base<Derived1>
    {
    enum { id = 1 };

    void invoke()
    {

    }
    };

    --
    Fabio.
     
    fabioppp, Apr 15, 2005
    #2
    1. Advertising

  3. "fabioppp" <fabioppp_it@yahoo[nospam].it> wrote in message
    news:EYQ7e.1240617$...
    > struct Derived1 : public Base<Derived1>
    > {
    > enum { id = 1 };
    > void invoke()
    > {}
    > };


    I'm a relative newbie compared to some of these guys, but it seems to me
    like you can't use a class in its own definition. How can the compiler know
    what Derived1 does until you finish defining it?

    - JFA1
     
    James Aguilar, Apr 15, 2005
    #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. Mike Smith

    ABC vs. CRTP?

    Mike Smith, Mar 2, 2005, in forum: C++
    Replies:
    7
    Views:
    915
    Dietmar Kuehl
    Mar 3, 2005
  2. CRTP question

    , Apr 17, 2006, in forum: C++
    Replies:
    2
    Views:
    393
  3. CRTP and Factories

    , Jul 25, 2006, in forum: C++
    Replies:
    2
    Views:
    330
  4. Noah Roberts

    CRTP

    Noah Roberts, Jan 12, 2007, in forum: C++
    Replies:
    6
    Views:
    897
    kwikius
    Jan 15, 2007
  5. Arash Partow

    Heterogeneous containers with CRTP

    Arash Partow, May 15, 2007, in forum: C++
    Replies:
    2
    Views:
    761
    Axter
    May 15, 2007
Loading...

Share This Page