Need some help Heritance

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
#include <iostream>

#include "Personnage.h"
#include "Pretre.h"
#include "PretreDemo.h"

using namespace std;

int main()
{
	string sName;

	cout << "Choisissez le nom du pretre" << endl;
	sName = cin.get();

	if(sName.length() >= 1)
	{
		Pretre p1;
		sName.clear();
	}
	else
		Pretre p1;

	p1.Pre();

	cout << "Choisissez le nom du pretre demoniste" << endl;
	sName = cin.get();

	if(sName.length() >= 1)
	{
		PretreDemo p2(sName);
		sName.clear();
	}
	else
		PretreDemo p2();


	cin.get();
	return 0;
}


Pretre.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
#include "Pretre.h"

Pretre::Pretre() : Personnage("Roger", "Marteau", 80, 40, 5, 10)
{

}

Pretre::Pretre(std::string sName) : Personnage(sName, "Marteau", 80, 40, 5, 10), m_AttaqueCeleste(0)
{
	m_AttaqueCeleste = new Sort("Attaque Celeste", 10, 5, 15);
}

void Pretre::Pre() const
{
	Personnage::Pre();
	std::cout << "Pretre" << std::endl;
}

Pretre::~Pretre()
{
	delete m_AttaqueCeleste;
}




The problem is at the p1.Pre() who I'm getting that p1 is not undetified
Error :identifier p1 is undefined

I need some help I,m lost
Last edited on
you are trying to access p1 in area where it is not visible (and actually doesn't exist anymore):
1
2
3
4
5
6
7
8
9
10
11
if(sName.length() >= 1)
{
	Pretre p1; //You have created p1 here
	sName.clear();
	//and it got destroyed here.
}
else
	Pretre p1;//Creating here...
	//...destroyed here

p1.Pre();//doesn't exist here 
Last edited on
Topic archived. No new replies allowed.