Arama butonu
Bu konudaki kullanıcılar: 1 misafir
3
Cevap
1140
Tıklama
0
Öne Çıkarma
C++ Destructor çağrısı?
W
10 yıl
Binbaşı
Konu Sahibi

Ön bilgi: kullandığım sınıflar;
Button.h
typedef void(*buttonmethod) (int buttonId, char buttonState); 

class Button
{
private:
int pin;
int id;
char oldState;
char read();
buttonmethod onstate;
public:
Button(buttonmethod onStateChange = nullptr, int Pin = 0);
//Button(method onStateChange);

void Attach(int Pin);
int GetPin();

int Read();
void Update();

int GetID();
void SetID(int ID);
};

Potentiometer.h
typedef void(*potmethod) (int potId, int potVal); 

class Potentiometer
{
private:
int id;
int sensivity;
int pin;
int val;

int read();

potmethod onval;
public:
Potentiometer(potmethod onStateChange = nullptr, int ID = 0, int Sensivity = 0);
~Potentiometer();

void Attach(int Pin);
int GetPin();

void SetSensivity(int SensivityValue);
int GetSensivity();

int Read();
void Update();

int GetID();
void SetID(int ID);
};

Joystick.h
class Joystick 
{
private:
int id;

Potentiometer *axises;
Button *buttons;

int potSize;
int buttonSize;

int potCount;
int buttonCount;

int freePotId(int base = 0);
int potIdCollapse(int id);

int freeButtonId(int base = 0);
int buttonIdCollapse(int id);

void reformButtons(const int size);
void reformPots(const int size);

public:
Joystick();
~Joystick();

char AddAxis(Potentiometer pot);
void SetPot(int potId, Potentiometer val);
Potentiometer GetPot(int potId);
void SetAxisSensivity(int SensivityValue);
int GetPotSize();
void SetPotSize(const int size);

char AddButton(Button button);
void SetButton(int buttonId, Button val);
Button GetButton(int buttonId);
int GetButtonSize();
void SetButtonSize(const int size);

int GetID();
void SetID(int ID);

void Update();
};

GS.h
class GS 
{

private:
Button *buttons;
Joystick *joysticks;
Potentiometer *pots;

int buttonCount;
int joystickCount;
int potCount;

int buttonSize;
int joystickSize;
int potSize;

void reformButtons(const int size);
void reformJoysticks(const int size);
void reformPots(const int size);

int freePotId(int base = 0);
char potIdCollapse(int id);

int freeButtonId(int base = 0);
char buttonIdCollapse(int id);

int freeJoystickId(int base = 0);
char joystickIdCollapse(int id);

public:
GS();
~GS();
void Loop();
char AddButton(Button button);
char AddJoystick(Joystick joystick);
char AddPotentiometer(Potentiometer pot);
int GetButtonSize();
void SetButtonSize(const int size);
int GetJoystickSize();
void SetJoystickSize(const int size);
int GetPotSize();
void SetPotSize(const int size);
};

main methodum;

GS gs = GS(); 
gs.SetJoystickSize(1);
Joystick j1 = Joystick();
j1.SetPotSize(3);
Potentiometer p1 = Potentiometer(ptn, 1, 1);
p1.Attach(1);
Potentiometer p2 = Potentiometer(ptn, 2, 1);
p2.Attach(2);
Potentiometer p3 = Potentiometer(ptn, 2, 1);
p3.Attach(3);
j1.AddAxis(p1);
j1.AddAxis(p2);
j1.AddAxis(p3);
gs.AddJoystick(j1);


Sorunum:
main metodundaki o son satır "gs.AddJoystick(j1);" execute edildikten sonra bir sebepten ötürü ilk resimdeki hatayı alıyorum.
Retry'a tıklayınca 2. resimdeki pencere geliyor, break deyince de 3. resimdeki yere yönlendiriyor beni. Program orada durduğunda watch ekranından axises'ın içeriğini şu şekilde görebiliyorum;
----------------------------------------------------------------------------------------------
this->axises[0] {id=1 sensivity=1 pin=1 ...} Potentiometer
id 1 int
sensivity 1 int
pin 1 int
val 0 int
onval 0x01181249 {Ground System.exe!ptn(int,int)} void (int, int) *
----------------------------------------------------------------------------------------------
this->axises[1] {id=2 sensivity=1 pin=2 ...} Potentiometer
id 2 int
sensivity 1 int
pin 2 int
val 0 int
onval 0x01181249 {Ground System.exe!ptn(int,int)} void (int, int) *
----------------------------------------------------------------------------------------------
this->axises[2] {id=0 sensivity=1 pin=3 ...} Potentiometer
id 0 int
sensivity 1 int
pin 3 int
val 0 int
onval 0x01181249 {Ground System.exe!ptn(int,int)} void (int, int) *

Tam olarak nedir hata anlamadım? Neden destructor çağırılmış onu da anlamadım?
axisesı oluşturma şeklim şöyle;
this->axises = new Potentiometer[size]; 
this->potCount = 0;
this->potSize = size;


Değiştirme şeklim şöyle;
char Joystick::AddAxis(Potentiometer pot) 
{
if (potCount < potSize)
{
if (potIdCollapse(pot.GetID()))
{
pot.SetID(freePotId());
}
axises[potCount++] = pot;
return 1;
}
else
{
return 0;
}
}


Genel olarak hatayla ilgili bilgilendirebilecek veya onun dışında yanlış yaptığım hatalı kullandığım şeyleri düzeltebilecek ufak bilgilendirmeler, yönlendirmeler çok yardımcı olacak, teşekkürler, iyi forumlar.
< Resime gitmek için tıklayın >< Resime gitmek için tıklayın >< Resime gitmek için tıklayın >