Help with passing pointers through objects

Hello, and thanks in advance.
I've been trying to figure pointers and referencing out for quite some time now but I just cant seem to get it.

Im trying to output(cout) some protected variables in the player class(Player.h) through the get_stats() function, im not sure whats wrong with it.
Im calling it through a display_player() function in UI.h

Also Visual Studios telling me the playerutilObject(in main) is deleted.

I really have no idea what im doing wrong, I've looked through every video and piece of text on pointers and I guess I just cant get it on my own, any help appreciated

Main.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
#include "stdafx.h"
#include <iostream>
#include <string>
#include "Enums.h"
#include "Player.h"
#include "UI.h"
using namespace std;

int main()
{
	Player_Util playerutilObj;
	UI uiObj;

	playerutilObj.set_talent(2);
	uiObj.display_player();
}


UI.h
1
2
3
4
5
6
7
#pragma once
class UI
{
public:
	int *temp[10];
	void display_player();
};


UI.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
#include "stdafx.h"
#include <iostream>
#include "Enums.h"
#include "Player.h"
#include "UI.h"
using namespace std;

void UI::display_player() {
    Player_Util playerutilObj;
    playerutilObj.get_stats(*temp[0], *temp[1], *temp[2], *temp[3], *temp[4],
		            *temp[5], *temp[6], *temp[7], *temp[8], *temp[9]);

	cout << "HP: "			<< temp[0] << endl;
	cout << "Essense: "	        << temp[1] << endl;
	cout << "XP: "			<< temp[2] << endl;
	cout << "Damage: "		<< temp[3] << endl;
	cout << "rDamage: "		<< temp[4] << endl;
	cout << "CritDmg: "		<< temp[5] << endl;
	cout << "rCritDmg: "	        << temp[6] << endl;
	cout << "Brawn: "		<< temp[7] << endl;
	cout << "Cunning: "		<< temp[8] << endl;
	cout << "Perception: "          << temp[9] << endl;
	}
}


Player.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
#pragma once
using namespace std;

struct Player
{
protected:
	int talent,
		&health, &essense, &experience,
		&damage0, &damage1, &critdamage0, &critdamage1,
		&brawn, &cunning, &perception;
};

class Player_Util : public Player {
public:

	void get_stats(int *a, int *b, int *c, int *d, int *e,
		       int *f, int *g, int *h, int *i, int *j);
	void set_talent(int x);

};


Player.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
58
59
60
61
62
63
#include "stdafx.h"
#include <iostream>
#include <string>
#include "Player.h"
#include "Enums.h"
using namespace std;

void Player_Util::get_stats(int *a, int *b, int *c, int *d, int *e,
	                    int *f, int *g, int *h, int *i, int *j) {
	*a = &health;      *b = &essense;     *c = &experience;
	*d = &damage0;	   *e = &damage1;
	*f = &critdamage0; *g = &critdamage1;
	*h = &brawn;       *i = &cunning;     *j = &perception;

}


void Player_Util::set_talent(int x) {
	switch (talent) {
	case warrior:
		health += 120;
		essense += 50;
		brawn += 5;
		cunning += 2;
		perception += 3;
		break;
	case stalker:
		health += 75;
		essense += 75;
		brawn += 1;
		cunning += 5;
		perception += 4;
		break;
	case scholar:
		health += 100;
		essense += 100;
		brawn += 0;
		cunning += 4;
		perception += 6;
		break;
	case barbarian:
		health += 150;
		essense += 20;
		brawn += 10;
		cunning += 0;
		perception += 0;
		break;
	case cutthroat:
		health += 50;
		essense += 50;
		brawn += 0;
		cunning += 10;
		perception += 0;
		break;
	case cultist:
		health += 75;
		essense += 75;
		brawn += 0;
		cunning += 0;
		perception += 10;
		break;
	}
}


Enums.h
1
2
3
4
5
6
7
8
9
10
11
#pragma once

enum talent
{
        warrior,
	stalker,
	scholar,
	barbarian,
	cutthroat,
	cultist
};
Last edited on
I pasted your program into an online compiler: check out diagnostics from clang, they make it more clear: https://wandbox.org/permlink/5ROcLoeVWgBivIu9

prog.cc:16:8: warning: struct 'Player' does not declare any constructor to initialize its non-modifiable members
struct Player
       ^
prog.cc:20:4: note: reference member 'health' will never be initialized
                &health, &essense, &experience,
                 ^
prog.cc:20:13: note: reference member 'essense' will never be initialized
                &health, &essense, &experience,
                          ^
prog.cc:20:23: note: reference member 'experience' will never be initialized
                &health, &essense, &experience,
                                    ^
prog.cc:21:4: note: reference member 'damage0' will never be initialized
                &damage0, &damage1, &critdamage0, &critdamage1,
                 ^
prog.cc:21:14: note: reference member 'damage1' will never be initialized
                &damage0, &damage1, &critdamage0, &critdamage1,
                           ^
prog.cc:21:24: note: reference member 'critdamage0' will never be initialized
                &damage0, &damage1, &critdamage0, &critdamage1,
                                     ^
prog.cc:21:38: note: reference member 'critdamage1' will never be initialized
                &damage0, &damage1, &critdamage0, &critdamage1,
                                                   ^
prog.cc:22:4: note: reference member 'brawn' will never be initialized
                &brawn, &cunning, &perception;
                 ^
prog.cc:22:12: note: reference member 'cunning' will never be initialized
                &brawn, &cunning, &perception;
                         ^
prog.cc:22:22: note: reference member 'perception' will never be initialized
                &brawn, &cunning, &perception;
                                   ^
prog.cc:44:17: error: call to implicitly-deleted default constructor of 'Player_Util'
    Player_Util playerutilObj;
                ^
prog.cc:25:21: note: default constructor of 'Player_Util' is implicitly deleted because base class 'Player' has a deleted default constructor
class Player_Util : public Player {
                    ^
prog.cc:20:4: note: default constructor of 'Player' is implicitly deleted because field 'health' of reference type 'int &' would not be initialized
                &health, &essense, &experience,
                 ^
Thanks for putting in the time dude, need to learn more about classes and constructors it would seem. Also thanks for showing me that clang has way better errors :p
Topic archived. No new replies allowed.