Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6870567
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T03:41:57+00:00 2026-05-27T03:41:57+00:00

#pragma once #include Player.h class Player; //class SmallHealth; const int kNumOfCards = 3; //for

  • 0
#pragma once
#include "Player.h"

class Player;
//class SmallHealth;

const int kNumOfCards = 3; //for Player class also
const int kCardLimit = 3;

class Cards
{
private:
protected:
    int turnsInEffect;
    Player *owner;
public:
    Cards()
    {turnsInEffect = 1;}
    void AssignOwner(Player &player)
    {
        owner = &player;
    }
    virtual void PlayCard()
    {}
    virtual ~Cards(void)
    {}

};

class SmallHealth : public Cards
{
public:
    void PlayCard()
    {
        turnsInEffect = 1;
        owner->SetHealth(owner->GetHealth() + 5);

        //check if health goes over
        if(owner->GetHealth() > owner->GetHealthLimit())
        {
            owner->SetHealth(owner->GetHealthLimit());
        }
        turnsInEffect--;
    }
};

I thought by declaring class Player I wouldn’t get these errors:

error C2027: use of undefined type 'Player

see declaration of ‘Player’

error C2227: left of '->SetHealth' must point to ...

Checking on error 2027, seems I have to explicitly have the whole class before the Cards class, but I thought the forward class declaration would make it unnecessary. How I have it set up is that Cards class is created and assigned a subclass by the Player class and stored in the Player class. The subclasses that inherit the Cards class will call upon the functions of the Player class. I’m having a tough time making sure the 2 classes identify each others classes.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T03:41:57+00:00Added an answer on May 27, 2026 at 3:41 am

    In that case, a forward declaration of a C++ class will just tell the compiler that the type you’re using is a class.

    This is often useful for headers, as you only need to know that the type is a class. Including the class’ header would take more compile time.

    But in the implementation, it’s different. With a forward class, the compiler will not know about its members, methods, etc.

    For that, you need to include the header file of the class.

    For instance, with only the forward class, you can’t do that:

    owner->GetHealth();
    

    As there is no way for the compiler to know the GetHealth method exists in your Player class, with just a forward class.

    Note you may also have a problem in your AssignOwner method, as you implement it using your header. I’m a bit rusty on C++, as I’m doing C most of the time, but I think you should try declaring only the prototype in the class header, and implement the actual method in your implementation file, after having included the correct header file.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I wrote class like this: #pragma once #include stdafx.h struct Date { private: int
I'm using VS2010 Ultimate. Having code: //file IntSet.h #include stdafx.h #pragma once /*Class representing
#pragma once #include LudoCore/Singleton.h class LudoTimer : public Singleton<LudoTimer> { friend class Singleton<LudoTimer>; public:
concerning the following piece of code : StaticEnum.h #pragma once #include <string> class StaticEnum
#pragma once #include <string> #include <vector> #include <stdint.h> class PasswordCrypt { public: PasswordCrypt(std::vector<uint8_t> buffer);
my code is: #pragma once #include stdafx.h #include <vector> #include field.h class output {
I have a header file like so: #pragma once #include gamestate.h #include ExitListener.h class
I have the following class: #pragma once #include <string> #include <iostream> class testclass {
In a .h if I have: #pragma once #include <xxxx.h> #include yyyy.h class AAAAAA;
I am having some trouble getting this simple code to work: #pragma once #include

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.