L
Lorn
Hopefully someone can help me out with this problem I'm having with 2d
vectors. My vector initialization looks like this:
struct Object {
double d1;
double d2;
int i1;
};
std::vector<std::vector <Object> > vMain;
std::vector<Object> vec;
/////
When I add objects in the vectors it looks like this:
Object stData2 = { 2, 2, 2};
Object stData3 = { 3, 3, 3};
Object stData4 = { 4, 4, 4};
vec.push_back(stData2);
vMain.push_back(vec);
vec.clear();
vec.push_back(stData3);
vMain.push_back(vec);
vec.clear();
/////
Ok, so far so good. My problem comes when I want to add a third vector
object into my vMain vector at a specified position. The following
gives me an error:
vec.push_back(stData4);
vMain[0].push_back(vec);
/////
The error I receive is:
error C2664: 'std::vector<_Ty>:ush_back' : cannot convert parameter 1
from 'std::vector<_Ty>' to 'const CTestDlg::Object &'
with
[
_Ty=CTestDlg::Object
]
and
[
_Ty=CTestDlg::Object
]
Reason: cannot convert from 'std::vector<_Ty>' to 'const
CTestAPIDlg::Object'
with
[
_Ty=CTestDlg::Object
]
No constructor could take the source type, or constructor
overload resolution was ambiguous.
/////
I have seen examples where the code above compiles and seemingly works.
What am I doing wrong? Any tips or suggestions would be very valuable
and much appreciated.
Thank you,
Lorn
vectors. My vector initialization looks like this:
struct Object {
double d1;
double d2;
int i1;
};
std::vector<std::vector <Object> > vMain;
std::vector<Object> vec;
/////
When I add objects in the vectors it looks like this:
Object stData2 = { 2, 2, 2};
Object stData3 = { 3, 3, 3};
Object stData4 = { 4, 4, 4};
vec.push_back(stData2);
vMain.push_back(vec);
vec.clear();
vec.push_back(stData3);
vMain.push_back(vec);
vec.clear();
/////
Ok, so far so good. My problem comes when I want to add a third vector
object into my vMain vector at a specified position. The following
gives me an error:
vec.push_back(stData4);
vMain[0].push_back(vec);
/////
The error I receive is:
error C2664: 'std::vector<_Ty>:ush_back' : cannot convert parameter 1
from 'std::vector<_Ty>' to 'const CTestDlg::Object &'
with
[
_Ty=CTestDlg::Object
]
and
[
_Ty=CTestDlg::Object
]
Reason: cannot convert from 'std::vector<_Ty>' to 'const
CTestAPIDlg::Object'
with
[
_Ty=CTestDlg::Object
]
No constructor could take the source type, or constructor
overload resolution was ambiguous.
/////
I have seen examples where the code above compiles and seemingly works.
What am I doing wrong? Any tips or suggestions would be very valuable
and much appreciated.
Thank you,
Lorn