Undefined reference to class::class

Im getting this damn error Again! It's really annoying and is really pissing me off honestly. Can you please help show me what is going on with my code. This is
main.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#include <iostream>
#include <string>
#include <vector>
#include "Player.h"

//Battleships Game
//
using namespace std;
//Enemy class later its on file
 class Enemy
{
public:
    Enemy();
      virtual void TheenemyHealth(){}
     virtual int EnemyDamage(int EnemyAttack){
int  Attack = EnemyAttack;
     Attack = 15;
     return Attack;
    }
private:
   int Attackpower = 0;
    int Strenght = 0;


};
Enemy::Enemy()
{
    Attackpower;
    Strenght;

}
class Monster :public Enemy
{
    public:
    void TheenemyHealth()
    {
        int Enemyhealth = 100;
    }
    int EnemyDamage(int EnemyAttack){
    int Attack = EnemyAttack;
    Attack = 5;
    }


};


using namespace std;
int main()
{
    Player *b = new Player(100,100);
    Player q;
bool battle;
ofstream p;
b->Healspell(p,battle);

}


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
#ifndef PLAYER_H
#define PLAYER_H

//player.h
class Player
{

public:
 Player(int Health, int Mana);

 ~Player();
void Healspell(Player &healing,bool fighting);

bool getbattle();
private:
 int Health = 100;
 int Mana = 100;
};

#endif // PLAYER_H


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#include "Player.h"
//Player.cpp file
Player::Player(int Health, int Mana)
{
   Health;
   Mana;

}
Player::~Player()
{

}

void Player::Healspell(Player &healing,bool fighting){
fighting = false;
do{
        healing.Health + 20;



}while(fighting = true);


}
Wow that was dry, this is the error (sorry for the lack of information in original post). I am getting a undefined reference from Player::Player() when I tried to call a new function with Player in main.
Also, I would like to know how will I be able to call this.
 
void Player::Healspell(Player &healing,bool fighting)

in main I don't know how I will be to call something into healing. That's also what I have been tried to figure out.
Your line 52 creates object 'q'. That requires default constructor.

Your class Player has a non-default constructor. Therefore, the compiler will not implicitly add the default constructor. You have to add the default constructor explicitly.


If a function takes a (reference to) Player and a bool as parameters, then you should call it with such parameters. Definitely not with a std::ofstream and a bool, like your current code does.


* So how will I create this please show me

* Again, show me how I will call it instead of just telling me.

Judging by your recent thread http://www.cplusplus.com/forum/beginner/168829/
you have trouble understanding function arguments.

The tutorials here have a page about functions and their arguments: http://www.cplusplus.com/doc/tutorial/functions/


I don't think that we should start to tell "what is going in your code". It will be much more beneficial to you, if you explain each line of your code to us first.
Topic archived. No new replies allowed.