How to create a vector?
-
Hi All, I have a member variable of data type double. Following is the variable double m_Value [7] [3]; Now I have to do the declaration by using vectors. so how I will declare it. I have to Initialize it by 0 also.......... Thanks
-
Hi All, I have a member variable of data type double. Following is the variable double m_Value [7] [3]; Now I have to do the declaration by using vectors. so how I will declare it. I have to Initialize it by 0 also.......... Thanks
Hi deadlyabbas,
const int ROW = 7; // Row
const int COLUMN = 3; // Column// same as - double m_Value [7] [3]; initialized with 0.0
// vector can be initialized by - vector<type>( size, DefaultValue );
vector< vector<double> > m_Value( ROW, vector<double>( COLUMN, 0.0 ));Best Regards, Jijo.
_____________________________________________________ http://weseetips.com[^] Visual C++ tips and tricks. Updated daily.
-
Hi deadlyabbas,
const int ROW = 7; // Row
const int COLUMN = 3; // Column// same as - double m_Value [7] [3]; initialized with 0.0
// vector can be initialized by - vector<type>( size, DefaultValue );
vector< vector<double> > m_Value( ROW, vector<double>( COLUMN, 0.0 ));Best Regards, Jijo.
_____________________________________________________ http://weseetips.com[^] Visual C++ tips and tricks. Updated daily.
Thanks Jijo. But the issue with this is that I am not able to make declaration and definition separately. If I do it like this in .h file
vector> m_Value;
and in .cpp file I do this
m_value(10,vector(3,0.0));
It gave me an error which says error C2064: term does not evaluate to a function taking 2 arguments
-
Thanks Jijo. But the issue with this is that I am not able to make declaration and definition separately. If I do it like this in .h file
vector> m_Value;
and in .cpp file I do this
m_value(10,vector(3,0.0));
It gave me an error which says error C2064: term does not evaluate to a function taking 2 arguments
You should be able to do this using the constructor initialization list. MyClass.h file
class CMyClass
{
private:
vector< vector<double> > m_Value;
};MyClass.cpp
CMyClass::CMyClass() : m_Value(ROW, vector<double>( COLUMN, 0.0 ))
{
}«_Superman_» I love work. It gives me something to do between weekends.
Microsoft MVP (Visual C++)