'Undefined' error

Discussion in 'C++' started by Peter Davis, Jul 17, 2012.

  1. Peter Davis

    Peter Davis Guest

    I'm trying to define a template class ...

    namespace abc
    {
    class Node;
    typedef boost::shared_ptr<Node> NodePtr;
    template <typename Derived> class Cloneable
    {
    public:
    virtual NodePtr clone() const
    {
    Derived *d = new Derived(static_cast<const
    Derived&>(*this));
    return d->makeNodePtr(); }
    };
    ....

    and then use that as a superclass of another class ...

    #include "abc/dom/Node.hpp" // The file above!
    namespace abc
    {

    class Node : public BaseObject, Cloneable<Node>
    {
    ....

    This follows, as I understand it, the 'curiously recurring template'
    pattern. However, when I try to compile (Visual Studio 2008), I get the
    error:
    C2504: 'CloneableImpl' : base class undefined.
    on the line defining class Node. I don't understand why, since the cpp
    file includes the header file in which the template Cloneable is
    defined, and they're in the same namespace.

    Any insights?

    Thanks!
    -pd


    --
    ----
    The Tech Curmudgeon
    http://www.techcurmudgeon.com
    Peter Davis, Jul 17, 2012
    #1
    1. Advertising

  2. Peter Davis

    Casey Guest

    "Cloneable" and "CloneableImpl" are different identifiers. I think you are missing the forest for the trees.
    Casey, Jul 17, 2012
    #2
    1. Advertising

  3. On 7/17/2012 10:33 AM, Peter Davis wrote:
    > I'm trying to define a template class ...
    >
    > namespace abc
    > {
    > class Node;
    > typedef boost::shared_ptr<Node> NodePtr;
    > template <typename Derived> class Cloneable
    > {
    > public:
    > virtual NodePtr clone() const
    > {
    > Derived *d = new Derived(static_cast<const
    > Derived&>(*this));
    > return d->makeNodePtr(); }
    > };
    > ...
    >
    > and then use that as a superclass of another class ...
    >
    > #include "abc/dom/Node.hpp" // The file above!
    > namespace abc
    > {
    >
    > class Node : public BaseObject, Cloneable<Node>
    > {
    > ...
    >
    > This follows, as I understand it, the 'curiously recurring template'
    > pattern. However, when I try to compile (Visual Studio 2008), I get the
    > error:
    > C2504: 'CloneableImpl' : base class undefined.
    > on the line defining class Node. I don't understand why, since the cpp
    > file includes the header file in which the template Cloneable is
    > defined, and they're in the same namespace.
    >
    > Any insights?


    Not with your incomplete code. See FAQ 5.8.

    This code:
    --------------------------------------------------
    namespace abc
    {
    class Node;
    typedef Node* NodePtr;
    template <typename Derived> class Cloneable
    {
    public:
    virtual NodePtr clone() const
    {
    Derived *d = new Derived(static_cast<const Derived&>(*this));
    return d->makeNodePtr();
    }
    };

    class BaseObject
    {

    };
    }

    namespace abc
    {
    class Node : public BaseObject, Cloneable<Node>
    {
    public:
    Node* makeNodePtr() { return new Node; }
    };
    }

    int main()
    {
    abc::Node blah;
    abc::Node* blahblah = blah.makeNodePtr();
    }
    --------------------------------------------------
    compiles fine with VC++ 2010. I don't have 2008 to test.

    V
    --
    I do not respond to top-posted replies, please don't ask
    Victor Bazarov, Jul 17, 2012
    #3
  4. Peter Davis

    Peter Davis Guest

    On 7/17/2012 11:06 AM, Casey wrote:
    > "Cloneable" and "CloneableImpl" are different identifiers. I think you are missing the forest for the trees.
    >


    Sorry. That was a typo in my attempt to simplify the example. In
    reality, everything is "CloneableImpl", but the problem occurs nonetheless.

    Thanks,

    -pd

    --
    ----
    The Tech Curmudgeon
    http://www.techcurmudgeon.com
    Peter Davis, Jul 17, 2012
    #4
  5. Peter Davis

    Peter Davis Guest

    On 7/17/2012 11:08 AM, Victor Bazarov wrote:
    > On 7/17/2012 10:33 AM, Peter Davis wrote:
    >> I'm trying to define a template class ...
    >> ...
    >> This follows, as I understand it, the 'curiously recurring template'
    >> pattern. However, when I try to compile (Visual Studio 2008), I get the
    >> error:
    >> C2504: 'CloneableImpl' : base class undefined.
    >> on the line defining class Node. I don't understand why, since the cpp
    >> file includes the header file in which the template Cloneable is
    >> defined, and they're in the same namespace.
    >>
    >> Any insights?

    >
    > Not with your incomplete code. See FAQ 5.8.
    >
    > This code:
    > --------------------------------------------------
    > --------------------------------------------------
    > compiles fine with VC++ 2010. I don't have 2008 to test.


    Thank you. I'm still not sure what was going on, but I found that
    forward declaring the cloneable class seems to work in VS2008:

    class Node;
    class Node : public BaseObject, Cloneable<Node>
    ....

    I have about 30 classes, 2nd- and 3rd-derivatives of BaseObject, and
    most built just fine without the forward declaration. When time permits,
    I'll do some more investigating and post any findings here.

    Thank you!

    -pd



    --
    ----
    The Tech Curmudgeon
    http://www.techcurmudgeon.com
    Peter Davis, Jul 18, 2012
    #5
  6. On 7/18/2012 9:33 AM, Peter Davis wrote:
    > On 7/17/2012 11:08 AM, Victor Bazarov wrote:
    >> On 7/17/2012 10:33 AM, Peter Davis wrote:
    >>> I'm trying to define a template class ...
    >>> ...
    >>> This follows, as I understand it, the 'curiously recurring template'
    >>> pattern. However, when I try to compile (Visual Studio 2008), I get the
    >>> error:
    >>> C2504: 'CloneableImpl' : base class undefined.
    >>> on the line defining class Node. I don't understand why, since the cpp
    >>> file includes the header file in which the template Cloneable is
    >>> defined, and they're in the same namespace.
    >>>
    >>> Any insights?

    >>
    >> Not with your incomplete code. See FAQ 5.8.
    >>
    >> This code:
    >> --------------------------------------------------
    >> --------------------------------------------------
    >> compiles fine with VC++ 2010. I don't have 2008 to test.

    >
    > Thank you. I'm still not sure what was going on, but I found that
    > forward declaring the cloneable class seems to work in VS2008:
    >
    > class Node;
    > class Node : public BaseObject, Cloneable<Node>
    > ...
    >
    > I have about 30 classes, 2nd- and 3rd-derivatives of BaseObject, and
    > most built just fine without the forward declaration. When time permits,
    > I'll do some more investigating and post any findings here.


    Well, unless you're unduly constrained to 2008, you should consider
    switching to 2010 or even to 2012 (which is in RC stage now).

    V
    --
    I do not respond to top-posted replies, please don't ask
    Victor Bazarov, Jul 18, 2012
    #6
    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. Gene Mat

    NET::NNTP Undefined value error

    Gene Mat, Jul 8, 2003, in forum: Perl
    Replies:
    0
    Views:
    1,693
    Gene Mat
    Jul 8, 2003
  2. Mike John

    Error: 'WScript' is undefined'

    Mike John, Jul 8, 2003, in forum: ASP .Net
    Replies:
    1
    Views:
    5,187
    Natty Gur
    Jul 8, 2003
  3. Mantorok Redgormor
    Replies:
    70
    Views:
    1,734
    Dan Pop
    Feb 17, 2004
  4. VK
    Replies:
    45
    Views:
    581
    Dr John Stockton
    Sep 12, 2006
  5. -Lost
    Replies:
    13
    Views:
    359
    Richard Cornford
    Jan 31, 2007
Loading...

Share This Page