Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > 'Undefined' error

Reply
Thread Tools

'Undefined' error

 
 
Peter Davis
Guest
Posts: n/a
 
      07-17-2012
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 200, 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

 
Reply With Quote
 
 
 
 
Casey
Guest
Posts: n/a
 
      07-17-2012
"Cloneable" and "CloneableImpl" are different identifiers. I think you are missing the forest for the trees.
 
Reply With Quote
 
 
 
 
Victor Bazarov
Guest
Posts: n/a
 
      07-17-2012
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 200, 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


 
Reply With Quote
 
Peter Davis
Guest
Posts: n/a
 
      07-17-2012
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

 
Reply With Quote
 
Peter Davis
Guest
Posts: n/a
 
      07-18-2012
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 200, 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

 
Reply With Quote
 
Victor Bazarov
Guest
Posts: n/a
 
      07-18-2012
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 200, 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


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
ERROR [HY000] [Microsoft][ODBC Microsoft Access Driver]General error Unable to open registry key 'Temporary (volatile) Jet DSN for process 0xffc Thread 0x228 DBC 0x437b94 Jet'. ERROR [IM006] [Microsoft][ODBC Driver Manager] Driver's SQLSetConnectAttr bazzer ASP .Net 0 03-30-2006 03:16 PM
Error connecting to SQLExpress 2005 locally (error: 26 - Error Locating Server/Instance Specified) hfk0 ASP .Net 2 03-27-2006 08:43 PM
ERROR [HY000] [Microsoft][ODBC Microsoft Access Driver]General error Unable to open registry key 'Temporary (volatile) Jet DSN for process 0x8fc Thread 0x934 DBC 0x437b94 Jet'. ERROR [IM006] [Microsoft][ODBC Driver Manager] Driver's SQLSetConnectAttr bazzer ASP .Net 1 03-24-2006 04:20 PM
ERROR [HY000] [Microsoft][ODBC Microsoft Access Driver]General error Unable to open registry key 'Temporary (volatile) Jet DSN for process 0x8fc Thread 0x934 DBC 0x437b94 Jet'. ERROR [IM006] [Microsoft][ODBC Driver Manager] Driver's SQLSetConnectAttr bazzer ASP .Net 0 03-24-2006 02:22 PM
Error 500: ERROR: Cannot forward. Writer or Stream already obtained. Error JavaQueries Java 1 03-01-2005 06:30 PM



Advertisments