LearningC | Introduction to Programming with C
kandi X-RAY | LearningC Summary
kandi X-RAY | LearningC Summary
Introduction to Programming with C
Support
Quality
Security
License
Reuse
Top functions reviewed by kandi - BETA
Currently covering the most popular Java, JavaScript and Python libraries. See a Sample of LearningC
LearningC Key Features
LearningC Examples and Code Snippets
Community Discussions
Trending Discussions on LearningC
QUESTION
I'm trying to do class inheritance in C++, but it obviously works very differently than in Python.
Right now, I have two classes, one called Player
that is the base class, and another one called HumanPlayer
that's the subclass.
The Player
class is an abstract class that has two ways of working.
The first is that it acts like a singleton. It has one static function called make_move
that people can call with an int
and a TicTacToeGame&
, and it will make a move for the player with that int
as the player's number in that game of TicTacToe
.
The second is that it works as a class for creating objects that have a player number as a property. So, if you construct an object with the class, you should get back an object with a player_number
property. Then, if you call the make_move
function with just a TicTacToeGame&
on the object, it will automatically plug in its player number and use the static class method to make the move in the game.
I want the same functionality for HumanPlayer
, except I just want to have to write a new static function for HumanPlayer
, and that's it, since the other functionality remains the same.
Here's the code:
...ANSWER
Answered 2018-May-23 at 23:57The redefinition of the static function with the same name is hiding the one you want to use.
Either rename it differently or add
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
Vulnerabilities
No vulnerabilities reported
Install LearningC
Support
Reuse Trending Solutions
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items
Find more librariesStay Updated
Subscribe to our newsletter for trending solutions and developer bootcamps
Share this Page