Error occurs when I try to call an inherited function in C++

Naq Z

I have 3 classes, GameObject, Building which inherits from GameObject, and PokemonCenter which inherits from Building. When I try to call a Building::ShowStatus() function in PokemonCenter I keep get a "invalid operands to binary expression" error.

Building.h

#ifndef BUILDING_H
#define BUILDING_H
#include "Point2D.h"
#include "GameObject.h"

class Building : public GameObject
{

private:
    unsigned int pokemon_count;

public:
    Building();
    Building(char,int, Point2D);
    void AddOnePokemon();
    void RemoveOnePokemon();
    void ShowStatus();
    bool ShouldBeVisible();

};

#endif

Building.cpp

#include "Building.h"
#include "GameObject.h"
#include <iostream>
using namespace std;

Building::Building()
{
    display_code = 'B';
    location;
    id_num = ' ';
    state = '0';
    pokemon_count = 0;
    cout << "Building default constructed";
}

Building::Building(char in_code,int in_id, Point2D in_loc)
{
    id_num = in_id;
    location = in_loc;
    display_code = in_code;
    state = '0';
    pokemon_count = 0;
    cout << "Building constructed";
}

void Building::ShowStatus()
{
    cout << "\"(" << pokemon_count << "\"pokemon is/are in this building";
}

PokemonCenter.h

#ifndef POKEMONCENTER_H
#define POKEMONCENTER_H
#include "Point2D.h"
#include "Building.h"

class PokemonCenter: public Building
{
private:
    unsigned int stamina_capacity;
    unsigned int num_stamina_points_remaining;
    double dollar_cost_per_stamina_point;
    PokemonCenter();
    PokemonCenter(int,double,unsigned int, Point2D);

public:
    bool HasStaminaPoints();
    unsigned int GetNumStaminaPointsRemaining();
    bool CanAffordStaminaPoints(unsigned int, Point2D);
    double GetDollarCost(unsigned int);
    unsigned int DistributeStamina(unsigned int);
    bool Update();
    void ShowStatus();
};


enum PokemonCenterStates
{
    STAMINA_POINTS_AVAILABLE = 0,
    NO_STAMINA_POINTS_AVAILABLE = 1
};


#endif

PokemonCenter.cpp

#include "PokemonCenter.h"
#include "Point2D.h"
#include "Building.h"
#include "GameObject.h"
#include <iostream>
using namespace std;

PokemonCenter::PokemonCenter()
{
    id_num = ' ';
    location;
    display_code = 'C';
    stamina_capacity = 100;
    num_stamina_points_remaining = stamina_capacity;
    dollar_cost_per_stamina_point = 5;
    state = STAMINA_POINTS_AVAILABLE;
    cout << "PokemonCenter default constructed";
}

PokemonCenter::PokemonCenter(int in_id, double stamina_cost, unsigned int stamina_cap, Point2D in_loc)
{
    id_num = in_id;
    location = in_loc;
    dollar_cost_per_stamina_point = stamina_cost;
    stamina_capacity = stamina_cap;
    num_stamina_points_remaining = stamina_capacity;
    state = STAMINA_POINTS_AVAILABLE;
    cout << "PokemonCenter constructed";

}

void PokemonCenter::ShowStatus()
{
cout << "Pokemon Center Status: " << Building::ShowStatus() << endl;
}

R Sahu

The problem is that the return type of Building::ShowStatus() is void. operator<< is not defined between std::ostream and void. Hence, you can't use

cout << "Pokemon Center Status: " << Building::ShowStatus() << endl;

Change that to:

cout << "Pokemon Center Status: ";
Building::ShowStatus();
cout << endl;

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

Fatal error: Call to a member function fetch_assoc() on a non-object occurs when i try to run my php

why i get "no attirubute error" when i try to call python function from c++

Undefined reference error when I try to call compiled NASM function from C program

I've got the error message when try to call API function

Why do I get an error message of NoneType object is not callable when I try to call this function?

Can anyone tell me why I get a error when i try to call this function?

It occurs #1054 Error when I call procedure in mysql

Why my QTextEdit inherited rich text editor always crash when I try to call textCursor()?

Error occurs when i set connectToSortable inside the drag function

How can I solve this error that occurs when I try to sort a nested list based on another nested?

Error when try to call javascript function in xslt (Java JDK 8)

Embedded python on c++. Error occurs when i change debugger

Exception occurs when I try to pass a custom error to client in spring boot application

Operator translate error occurs when I try to convert onnx file to caffe2

Template is being rendered as plain text when I try to call a function

Call to a member function when i try to detach data (laravel)

Swift 2.0 makes error when i try to call in iPhone

Try and except returns error, however when run without, no error occurs?

Failed to load resource: the server responded with a status of 500 (Internal Server Error) this error occurs when I try to upload an image

I got an error in a function call of an array in C?

Function name not defined error when i try to use recursion

Error: use of deleted function when I try to use a reference

Except function is always executed when I try and give it a specific error

Probleme when i call a function in c

Why does the error occurs then I try to utilize pzRDExportWrapper in Pega 7.1.8?

I try to get a football game schedule from Google and this error occurs

An error occurs when I start my system

Error occurs when i transmit data with USART

An error occurs when I try to login my application in my local env, with Argument #1 ($user) must be of type Illuminate\Contracts\Auth\Authenticatable