Vector member data Error

Hello everyone,

Could you please tell me why i got an error on this line vector<vector<double>> vectorCurve(1,vector<double>(2)) in the code below?

My second question is : I want that vectorCurve have the size of mCurve. But since the size mCurve is not know yet (but it is known when Curve is instantiated), how can I do to make vectorCurve have the size of mCurve ?


Thank you in advance!
Regards

1
2
3
4
5
6
7
8
9
class Curve
{
    private:
    map<string, double> mCurve;
    vector<vector<double>> vectorCurve(1,vector<double>(2));
    
    public:  
    Curve( map<string, double> Curve_);
};
Member variables are normally initialized in the constructor's initializer list.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
class Curve
{
    private:
    map<string, double> mCurve;
    vector<vector<double>> vectorCurve;
    
    public:  
    Curve( map<string, double> Curve_);
};

Curve::Curve(map<string, double> Curve_)
:   vectorCurve(1,vector<double>(2))
{
    // ...
}


Since C++11 it is possible to initialize data members where they are defined but then you need to use { } instead of ( ).
1
2
3
4
5
6
7
8
9
class Curve
{
    private:
    map<string, double> mCurve;
    vector<vector<double>> vectorCurve{1,vector<double>(2)};
    
    public:  
    Curve( map<string, double> Curve_);
};

Last edited on
As for your second question, if you initialize the members in the constructor you can easily pass Curve_.size() to the constructor of vectorCurve.
Last edited on
Oh great! thanks for the accurate answer!

Regards
Topic archived. No new replies allowed.