PDA

View Full Version : default on class' public data


baray98
28th July 2008, 19:52
My class has a method that takes a class ( data class) as parameter and I want to put a default value if the caller won't supply it like class::function(int a = 3); kinda thing.

so here's what i did



class A
{
public:
class B
{
int x;
};
A()
{ defaultB.x = 3};
run(B options = defaultB); // compiler complains about non-static defaultB which is correct
private:
B defaultB;
};


do you guys know of any way that i can implement default on my methods passing a class ?

baray98

wysota
28th July 2008, 21:11
Make defaultB a static object or construct defaultB inside the constructor or provide a constructor for B that will create defaultB and call that constructor as the default parameter for the method from A.

baray98
29th July 2008, 03:04
I did the assigning of defaults in my constructor

baray98