0

Possible Duplicate:
The type in a dynamic_cast must be a pointer or reference to a complete class type, or void *

I've got a namespace Fuzzy and it has an abstract class called CuteDog (that inherits from another abstract class).

I'm writing a new class called PuppyArmy

I'd like to have a pointer to a CuteDog in PuppyArmy and in my header file I'm trying this.

namespace Fuzzy { class CuteDog }

using namespace Fuzzy;

class PuppyArmy { 
  ...
  CuteDog *cute;
}

then when in my cpp file i've got this

using namespace Tough;

....
cute = dynamic_cast<::Fuzzy::CuteDog*>(foo()); // where foo() returns the parent class of CuteDog*

The compiler is telling me

 C2440: '=' : cannot convert from Fuzzy::CuteDog * to PuppyArmy::Fuzzy::CuteDog *

Any pointers to what I'm doing wrong here?

Community
  • 1
  • 1
Boumbles
  • 2,473
  • 3
  • 24
  • 42
  • 1
    Try changing `dynamic_cast<::Fuzzy..` to `dynamic_cast< ::Fuzzy...` because my compiler thinks the `<:` is the beginning of a trigraph/digraph. – David G Nov 02 '12 at 19:09
  • Once I fixed your transcription errors, it [works fine](http://ideone.com/qP50mX) for me. I think perhaps you're not telling us something. Please post a short, complete program that demonstrates your error. http://SSCCE.ORG/ – Robᵩ Nov 02 '12 at 20:26

2 Answers2

1

It looks like you didnt include header file where you defines CuteDog implementation

Denis Ermolin
  • 5,530
  • 6
  • 27
  • 44
1

In case someone is lead here by the title. This is how to forward declare a class (abstract or not) from a different name space:

namespace different {
  class SomeClass;
}
Johan Lundberg
  • 26,184
  • 12
  • 71
  • 97