Parameterised structure constructor

struct buf
{
int a;
buf(){
cout<<"in stuct default\n";
a = 3;
}
buf(int x) {
a = x;
cout<<"in stuct parameterizd\n";
}
};

class A
{
public:
struct buf o1(5);
A(){ }
};

int main()
{
A ob1;
}

Can anyone tell me whats wrong with this code.
I'm getting a compilation error as
sample.cpp:19: error: expected identifier before numeric constant
sample.cpp:19: error: expected â,â or â...â before numeric constant

Thanks in Advance
Murali
I think that c++0b allows that in a way. (I don't remember the syntax)
You could do
1
2
3
4
5
class A{
public:
  buf o1;
  A(): o1(15) /*initialization list, to call parent and members constructors*/{}
};
The C++11 syntax is buf o1=5; or buf o1{5};, but you need a recent compiler for that (gcc 4.7 or clang 3.0).
Topic archived. No new replies allowed.