Default arguments, etc ..
From: ma740988 (ma740988_at_pegasus.cc.ucf.edu)
Date: 03/16/04
- Next message: Mike Wahler: "Re: Converting hex string to ASCII"
- Previous message: Xenzeo: "Re: Converting hex string to ASCII"
- Next in thread: B. v Ingen Schenau: "Re: Default arguments, etc .."
- Reply: B. v Ingen Schenau: "Re: Default arguments, etc .."
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: 15 Mar 2004 16:51:39 -0800
Some questions I've - sort of wrestled with earlier today.
1.
Is there a way to declare a variadiac function in a Base class? Put
another way. The function Compute (below) that forms a part of the
Base class differs only in the amount of arguments. So I was curious
to know if there's a way to say "virtual void Compute (int idx, ... )
= 0;"? Simply: One function, prototyped virtual function in Base
class and having multiple implementations for it which differs by
arguments
2.
Would it make sense to have var1 and var2 as part of the base class as
opposed to repeating them in the derived?
3.
Default args to a function are the last entries within the function
signatures.
This might be a language designer question but any insights on why
this is? In other words:
void FOO::ComputeLikeCrazy( int idx, int kdx = 5 ) { /* stuff */ }
^^^^^^^^^^^
Default args
void FOO::DoASpecialThing( int idx, int jdx = 5, int kdx = 6 ) { /*
stuff */ }
^^^^^^^^^^^^^^^^^^^^^^^^
Default args
I tweaked an implementation that I thought would be (formerly
overloaded) better suited with default args. Trouble is the there was
6 args with the second argument being the culprit. So now in the
declaration I moved the second argument to the sixth but the effects
rippled throughout.. You get the picture. Minor details nonetheless.
..
// the code
class Base
{
private:
protected:
// float var1;
// float var2;
// more
public:
virtual void Compute( int idx ) = 0;
virtual void Compute( int idx, int jdx ) = 0;
virtual void Compute( int idx, int jdx, int kdx ) = 0;
};
class Derived1 : public Base
{
private:
float var1;
float var2;
// lots more
public:
Derived1 ( float var1_, float var2_ ) : Base(), var1(var1_),
var2(var2_)
{
}
~ Derived1 () { }
void Compute ( int idx ) // Compute with one argument
{
// do something
}
};
class Derived2 : public Base
{
private:
float var1;
float var2;
// lots more
public:
Derived2 ( float var1_, float var2_ ) : Base(), var1(var1_),
var2(var2_)
{
}
~ Derived2 () { }
void Compute ( int idx, int jdx ) // Compute with two arguments
{
// do something
}
};
As always. Thanks for your time and many thanks for the individuals
who take the time on a continuum to enlighten us - or at least me.
Mark
------------------------------------------------------------------------
If I wanted to measure the natural resonances of any object
-- bell, Helmholz resonator -- I imagine that I would get a better
result by rigging up some kind of continuous exciter than by
attempting to analyze an impulse response
- Next message: Mike Wahler: "Re: Converting hex string to ASCII"
- Previous message: Xenzeo: "Re: Converting hex string to ASCII"
- Next in thread: B. v Ingen Schenau: "Re: Default arguments, etc .."
- Reply: B. v Ingen Schenau: "Re: Default arguments, etc .."
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|