In contrast to C#, this declaration;
Player player;
…is an instantiation of the type Player
, which means that by the time you’re assigning it inside the constructor, it has already been constructed without a parameter.
What you need to do is to tell the class how to initialize player
in what is called an initializer list that you append to the constructor header;
Game::Game(void) : player(100) { ...
…which tells the compiler to use that constructor to initialise player
in the first place instead of first using the default no-parameter constructor and then assigning to it.
Related Posts:
- Understanding Python super() with __init__() methods [duplicate]
- Is it possible to make abstract classes in Python?
- What is the difference between private and protected members of C++ classes?
- C++ [Error] no matching function for call to
- How do I define string constants in C++?
- C++ variable has initializer but incomplete type?
- What is predicate in C++?
- Here is some error with my .h file which show [Error] unterminated #ifndef when I include my class template in it
- Expression must have class type
- When should you use a class vs a struct in C++?
- Using two CSS classes on one element
- c++ “Incomplete type not allowed” error accessing class reference information (Circular dependency with forward declaration)
- Why is enum class preferred over plain enum?
- How to assign multiple classes to an HTML container?
- What does ‘super().__init__()’ mean in python 3.x?
- How to assign multiple classes to an HTML container?
- Why am I getting this redefinition of class error?
- Single class has a Class Redefinition Error
- C++ Linked List Node with class
- Inheriting constructors
- (->) arrow operator and (.) dot operator , class pointer
- Python: How do I make a subclass from a superclass?
- Inheriting constructors
- Separating class code into a header and cpp file
- how to define -std=c++11 as default in g++
- Pointer to incomplete class type is not allowed
- Why am I getting this redefinition of class error?
- Difference between ‘cls’ and ‘self’ in Python classes?
- no default constructor exists for class
- Getting error “a nonstatic member reference must be relative to a specific object” while both member are in the same class
- Error “C++ requires a type specifier for all declarations whilst defining methods”
- What are the differences between struct and class in C++?
- error C2011: ” : ‘class’ type redefinition
- The compiler is complaining about my default parameters?
- C++ Linked List Node with class
- Getting error: ISO C++ forbids declaration of with no type
- cannot declare variable ‘’ to be of abstract type ‘’
- How to call a parent class function from derived class function?
- “used without template parameters”
- QltAW.png
- expected constructor, destructor, or type conversion before ‘(’ token
- C++ Class ‘undeclared identifier”
- c++ “Incomplete type not allowed” error accessing class reference information (Circular dependency with forward declaration)
- Base class undefined
- What is object slicing?
- Warning: non-static data member initializers only available with -std=c++11 or -std=gnu++11?
- Why is inherited member not allowed?
- What is the meaning of a C++ Wrapper Class?
- Very basic inheritance: error: expected class-name before ‘{’ token
- Does C++11 have C#-style properties?
- G++ undefined reference to class::function
- Creating an instance of class
- Class template inheritance C++
- How do you implement a class in C?
- uml classdiagram constructor with parameters
- expected primary-expression before ‘]’ token
- Struct inheritance in C++
- C++ calling base class constructors
- Does C have classes?
- error C2039: ‘string’ : is not a member of ‘std’, header file problem
- istream and ostream problem – C++
- Struct with template variables in C++
- error: no member function declared in class
- Error: invalid use of member in static member function
- What does the variable $this mean in PHP?
- Is “delete this” allowed in C++?
- What is a segmentation fault?
- How many spaces for tab character(\t)?
- How to create a dynamic array of integers
- How to create a dynamic array of integers
- Linker Error C++ “undefined reference ” [duplicate]
- How do I build a graphical user interface in C++? [closed]
- C++ convert from 1 char to string?
- How do I build a graphical user interface in C++? [closed]
- convert a char* to std::string
- system(“pause”); – Why is it wrong?
- Pause Console in C++ program
- What is the purpose of the word ‘self’?
- system(“pause”); – Why is it wrong?
- Pause Console in C++ program
- How to implement 2D vector array?
- Why the switch statement cannot be applied on strings?
- What is the difference between g++ and gcc?
- How to use setprecision in C++
- How to dynamically allocate arrays in C++
- What does (~0L) mean?
- How to dynamically allocate arrays in C++
- What is the best way to use a HashMap in C++?
- What is the best way to use a HashMap in C++?
- What are the differences between a pointer variable and a reference variable in C++?
- What does ‘super’ do in Python? – difference between super().__init__() and explicit superclass __init__()
- Why do we need virtual functions in C++?
- Why in C++ do we use DWORD rather than unsigned int? [duplicate]
- What is an undefined reference/unresolved external symbol error and how do I fix it?
- Sleep for milliseconds
- How to convert string to char array in C++?
- How can I convert a std::string to int?
- Easiest way to convert int to string in C++
- What is the difference between float and double?
- Why is “using namespace std;” considered bad practice?