May 03, 2008 getting a classes array | ||||
|---|---|---|---|---|
| ||||
the following chrashes what do i do wrong? how does one manipulate class A's mVector array?
thanks
class A {
private:
int mVector[20] = 0;
public:
int* Self() {
return mVector.ptr;
}
bool StatusErrors() {
if((this.mVector[0] == 1) && (this.mVector[1] > 0))
return true;
return false;
}
void Reset() {
for(int i = 0; i < 20; i++)
mVector[i] = 0;
}
}
class B {
private:
A aa = new A;
public:
bool test() {
....
do some stuff
int i = somefunction(aa.Self());
if(aa.StatusErrors())
return false;
aa.Reset(); <------ crashes here
int i = somefunction1(aa.Self());
if(aa.StatusErrors())
return false;
}
}
| ||||
May 03, 2008 Re: getting a classes array | ||||
|---|---|---|---|---|
| ||||
Posted in reply to lurker | "lurker" <lurker@lurker.com> wrote in message news:fvgv7p$1gu7$1@digitalmars.com... > void Reset() { > for(int i = 0; i < 20; i++) > mVector[i] = 0; > } > } Slicing is fun. That loop can be replaced with "mVector[] = 0;" > class B { > private: > A aa = new A; This line doesn't even compile. You can't use a 'new' expression to initialize a member like in Java/C#. A aa; this() { aa = new A; } > bool test() { > .... > do some stuff > int i = somefunction(aa.Self()); > if(aa.StatusErrors()) > return false; > aa.Reset(); <------ crashes here > int i = somefunction1(aa.Self()); > if(aa.StatusErrors()) > return false; > } > } The only error I get when I run this code is an assertion at the end of test() saying that it's missing a return. You'll only get that error if you compile with -debug though. I don't get any error upon calling Reset. | |||
Copyright © 1999-2021 by the D Language Foundation
Permalink
Reply