M
Martin Magnusson
Hi,
I have defined a method of a base class which writes to a C-style array
without initializing it. (No, I don't like C arrays either, but I have
to use it here because of another library I'm using.) Calling this
without first allocating memory would of course give a run-time error,
but what puzzles me is that I get a segmentation fault when this method
is defined, even if it is never called at all! Is that normal?
The function looks like below, and the seg fault seems to originate from
a line where I call TS::Clone().
class S
{
//...
virtual void Skew( int* result ) const
{
vector<Real> v = this->AsReals();
for (unsigned i = 0; i < v.size(); ++i)
result = (int)rint(v);
}
virtual S* Clone() const = 0;
};
class TS : public S
{
//...
// does not override Skew()
TS* TS::Clone() const
{
return new TS(*this);
}
};
I have defined a method of a base class which writes to a C-style array
without initializing it. (No, I don't like C arrays either, but I have
to use it here because of another library I'm using.) Calling this
without first allocating memory would of course give a run-time error,
but what puzzles me is that I get a segmentation fault when this method
is defined, even if it is never called at all! Is that normal?
The function looks like below, and the seg fault seems to originate from
a line where I call TS::Clone().
class S
{
//...
virtual void Skew( int* result ) const
{
vector<Real> v = this->AsReals();
for (unsigned i = 0; i < v.size(); ++i)
result = (int)rint(v);
}
virtual S* Clone() const = 0;
};
class TS : public S
{
//...
// does not override Skew()
TS* TS::Clone() const
{
return new TS(*this);
}
};