C
ChristophK
Hallo,
this is my first post and I hope I'm doing well, but if not, please let
me know.
My problem:
First all classes and a main-file (I simplified everything to get to
the core of the problem):
/*---------------- start of code ---------------------------*/
#include <iostream>
/*! -------- class A --------- */
class A
{
public:
A(){};
~A(){};
void func(double* value);
protected:
double* classvalue;
};
void A::func(double* value)
{
std::cerr << "-DEBUG- A::func - this: " << this << std::endl;
classvalue = value;
}
class ADerublic A
{
public:
ADer(){};
~ADer(){};
};
//yes, I need this class, though it looks needless
/*! -------- class B --------- */
class B
{
public:
B(){};
B(int Nr);
~B(){delete cA;};
A* getA(int i) {return cA + i;};
void func(int start, int end, double* value);
private:
A* cA;
};
B::B(int Nr)
{
cA = new A[Nr];
}
void B::func(int start, int end, double* value)
{
for(int i=start; i<end; ++i)
{
cA.func(value);
}
}
class BDerublic B
{
public:
BDer(){};
BDer(int Nr);
~BDer(){};
ADer* getA(int i) {return cA + i;};
private:
ADer* cA;
};
BDer::BDer(int Nr)
{
cA = new ADer[Nr];
}
/*! -------- main --------- */
BDer* mBDer;
int main(int argc, char **argv)
{
mBDer = new BDer(10);
std::cerr << "-DEBUG- main - A: " << mBDer->getA(0) << std::endl;
mBDer->func(0, 10, 0);
}
/*---------------- end of code ---------------------------*/
I'm able to compile this cpp file with:
g++ -o test test.cpp
When I run the my programm a strange (at least for me) thing happens:
-DEBUG- A::func - this: 0
Segmentation fault
Can anyone tell me what I'm doing wrong?
Thanks in advance for all help that I get
Greetings
Christoph
this is my first post and I hope I'm doing well, but if not, please let
me know.
My problem:
First all classes and a main-file (I simplified everything to get to
the core of the problem):
/*---------------- start of code ---------------------------*/
#include <iostream>
/*! -------- class A --------- */
class A
{
public:
A(){};
~A(){};
void func(double* value);
protected:
double* classvalue;
};
void A::func(double* value)
{
std::cerr << "-DEBUG- A::func - this: " << this << std::endl;
classvalue = value;
}
class ADerublic A
{
public:
ADer(){};
~ADer(){};
};
//yes, I need this class, though it looks needless
/*! -------- class B --------- */
class B
{
public:
B(){};
B(int Nr);
~B(){delete cA;};
A* getA(int i) {return cA + i;};
void func(int start, int end, double* value);
private:
A* cA;
};
B::B(int Nr)
{
cA = new A[Nr];
}
void B::func(int start, int end, double* value)
{
for(int i=start; i<end; ++i)
{
cA.func(value);
}
}
class BDerublic B
{
public:
BDer(){};
BDer(int Nr);
~BDer(){};
ADer* getA(int i) {return cA + i;};
private:
ADer* cA;
};
BDer::BDer(int Nr)
{
cA = new ADer[Nr];
}
/*! -------- main --------- */
BDer* mBDer;
int main(int argc, char **argv)
{
mBDer = new BDer(10);
std::cerr << "-DEBUG- main - A: " << mBDer->getA(0) << std::endl;
mBDer->func(0, 10, 0);
}
/*---------------- end of code ---------------------------*/
I'm able to compile this cpp file with:
g++ -o test test.cpp
When I run the my programm a strange (at least for me) thing happens:
-DEBUG- main - A: 0x80493f4./test
-DEBUG- A::func - this: 0
Segmentation fault
Can anyone tell me what I'm doing wrong?
Thanks in advance for all help that I get
Greetings
Christoph