-4
void test() 
{   
    Token test();   
    Actor* check;   
    check = dynamic_cast<Actor*>(test); 
}

This method gives me the following error and underlines the test in the braces with red. The operand of a pointer dynamic_cast must be a pointer to a complete class type

How do i fix this? By the way Actor inherits from Token. Here's the code from Tokens header file.

#pragma once
#include <string>
class Token
{
public:
    Token();
    Token(int x, int y);
    bool IsDead();
    ~Token();
    char Symbol();
    int X, Y;
    bool clear;
    bool indestructable;
    int health;
    int damage, rangeDamage;
    //bool npc;
    char character;
    std::string ToString();
    std::string name;
    bool turnCompleted;
    void SetProfile(char Name);
};
Remy Lebeau
  • 555,201
  • 31
  • 458
  • 770
user3330027
  • 1
  • 1
  • 2

1 Answers1

3

First of all you are not creating instance of class Token called test but rather declare a function test() that returns Token.

Second you can try to convert pointer to Token, not object instance, so you should take address:

void test()
{
     Token test;
     Actor* check = dynamic_cast<Actor*>(&test);
}

Third, you say that Actor inherits from Token, but Token does not have any virtual functions, so you cannot use dynamic_cast on it. A good candidate in your case is Token's destructor.

Remy Lebeau
  • 555,201
  • 31
  • 458
  • 770
Slava
  • 43,454
  • 1
  • 47
  • 90