On 2006-01-05 14:21:58 -0500, "Michael" <femi@hrz.tu-chemnitz.de> said:
[color=blue]
> Hello,
>
> I want to use an object (LowCut) within another object
> (SampleRateConverter) like it is written as follows:
>
> class SampleRateConverter
> {
> public:
> SampleRateConverter( int iSourceSampleRate, int iTargetSampleRate )
> {
> LowCut = LowPassFilter(dCutoff, 512, BLACKMAN); // here
> debugger calls first constructor and then destructor[/color]
That is because you are creating a temporary object with the
expression (LowPassFilter(dCutoff, 512, BLACKMAN)). This temporary is
then copied via assignment to the instance variable LowCut, and is then
destroyed (hence the call to the destructor).
[color=blue]
> }
>
> private:
> LowPassFilter LowCut;
>
> void doSomething();
> };[/color]
Try this (this avoids the creation of a temporary object, and
initializes the member variable directly):
class SampleRateConverter
{
public:
SampleRateConverter( int iSourceSampleRate, int iTargetSampleRate )
: LowCut(dCutoff, 512, BLACKMAN)
{}
private:
LowPassFilter LowCut;
void doSomething();
};
[color=blue]
> I used the debugger and realized:
> After calling the constructor for LowPassFilter within
> SampleRateConverter, the destructor of LowPassFilter is called
> automatically.
>
> That means, the Filter becomes destroyed immediately. So, I cannot use
> it in the method doSomething. The Filter allocates a buffer in memory
> for storing information.[/color]
this suggests to me that you haven't properly implemented an assignment
operator (or, odds are, copy constructor) for the class LowPassFilter.
--
Clark S. Cox, III
clarkcox3@gmail.com