is it possible to initialize a structure via initializer list

Jan 25, 2011 at 12:39am
is it possible to initialize an structure using the constructor initialize list. i tried this but it doesnt work.


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
struct test
{
    int varone;
    int vartwo;
};

class example
{
public:
    example(int one, int two) : mtest.varone(one) , mtest.vartwo(two) {}


private:
    test mtest;
};
Jan 25, 2011 at 12:43am
1
2
3
4
5
6
7
8
9
10
11
12
13
14
struct test
{
    test( int one, int two ) : varone( one ), vartwo( two ) {}
    int varone;
    int vartwo;
};

class example
{
    public:
        example( int one, int two ) : mtest( one, two ) {}
    private:
        test mtest;
};

Jan 25, 2011 at 12:54am
oh i see. ok thanks for the fast reply.
Topic archived. No new replies allowed.