Initialization List Redudancy

Hello, I am wondering what would be the appropriate way to go about this:

I am making a class which can be initialized with either an int or a string. I also want the constructor to initialize some member variables. This looks like this:

1
2
3
4
5
6
7
8
9
class Some_Class {
private:
    int member1;
    int member2;

public:
    Some_Class(std::string arg) : member1(10), member2(20) {}
    Some_Class(int arg) : member1(10), member2(20) {}
};


This should be correct but it seems redundant. Is there a more appropriate way to do this?

Thank you.
With the current standard, the closest you can get is to do something like this:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
class Some_Class
{
private:
    int member1;
    int member2;

    void Construct()
    {
        member1 = 10;
        member2 = 20;
    }

public:
    Some_Class(std::string arg) { Construct(); }
    Some_Class(int arg) { Construct(); }
};


It's not ideal, but it will work for most things.

C++0x has better solutions, but it hasn't been finalized yet (it's taking forever!)
Topic archived. No new replies allowed.