Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

(Ab) Wann arbeitet ein Pointer korrekt?

16 views
Skip to first unread message

Heinz-Mario Frühbeis

unread,
Jul 20, 2017, 12:40:05 PM7/20/17
to
Hallo,

erst mal ein kleines Koonstrukt...

struct s_AreaColor_Part{
cRGB Back;
cRGB BackA;
cRGB Fore;
cRGB ForeA;
cRGB Border;
cRGB BorderA;
cRGB Border_Akt;
cRGB BorderA_Akt;
};

struct s_AreaColors{
cRGB Transparent;
s_AreaColor_Part A;
s_AreaColor_Part B;
s_AreaColor_Part C;
s_AreaColor_Part Disabled;
s_AreaColor_Part Alert_A;
s_AreaColor_Part Alert_B;
s_AreaColor_Part Alert_C;
};

class x {
s_AreaColors mColors;
s_AreaColor_Part *mColorPart[7];
x();
int mStatus;
void Create();
void Refresh();
}

x::x(){ // So funktioniert es nicht...
this->mStatus = 0;
this->mColorPart[0] = &this->mColors.A;
this->mColorPart[1] = &this->mColors.B;
this->mColorPart[2] = &this->mColors.C;
this->mColorPart[3] = &this->mColors.Alert_A;
this->mColorPart[4] = &this->mColors.Alert_B;
this->mColorPart[5] = &this->mColors.Alert_C;
this->mColorPart[6] = &this->mColors.Disabled;
}

void x::Create(){ // So aber schon!
this->mColorPart[0] = &this->mColors.A;
this->mColorPart[1] = &this->mColors.B;
this->mColorPart[2] = &this->mColors.C;
this->mColorPart[3] = &this->mColors.Alert_A;
this->mColorPart[4] = &this->mColors.Alert_B;
this->mColorPart[5] = &this->mColors.Alert_C;
this->mColorPart[6] = &this->mColors.Disabled;
}

void x::Refresh(){
s_AreaColor_Part *c = this->mColorPart[this->mStatus];
...
}

Wenn ich this->mColorPart im Konstruktor festlege, dann bekomme ich in
Refresh() "merkwürdige" Werte...

Aber, wenn this->mColorPart in z. Bsp. Create() festlege, dann bekomme
ich die Werte, die vorab auch übergeben worden sind!

Klar...: Warum?
Wieso klappt das nicht, wenn this->mColorPart im Konstruktor festgelegt
wird?
Ich meine, es ist doch ein Pointer und da dürfte/sollte<?> es doch egal
sein, wann ob/was gemacht wird, da this->mColorPart[] ja eben "nur" ein
Pointer ist...

Schon mal Danke.
H-MF

Markus Schaaf

unread,
Jul 21, 2017, 7:10:03 AM7/21/17
to
Am 19.07.2017 um 18:56 schrieb Heinz-Mario Frühbeis:

> Wenn ich this->mColorPart im Konstruktor festlege, dann bekomme ich in
> Refresh() "merkwürdige" Werte...
>
> Aber, wenn this->mColorPart in z. Bsp. Create() festlege, dann bekomme
> ich die Werte, die vorab auch übergeben worden sind!

Das Problem wird irgendwo beim (evtl. nicht vorhandenen) C'tor-Aufruf
oder zwischen C'tor und Refresh() liegen. Wenn Du bessere Antworten
willst, poste ein übersetzbares, komplettes Beispiel, nicht länger als
eine Bildschirmseite.

MfG
0 new messages