怀疑在向量c ++ inerst api [英] doubt in vector c++ inerst api

查看:115
本文介绍了怀疑在向量c ++ inerst api的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有类指针的插入函数:



代码如下:

i have insert function with class pointer :

the code is as follows :

InsertAt(int ptNum, myclass *point2Array)
{
const MtPoint2d * PointArray = point2Array->GetData();
	if (PointArray == NULL) 
	{
		return; 
	}

m_PointVectors.insert(m_PointVectors.begin() + ptNum, *point2Array);
}





这不是wortking你可以告诉任何其他soulution.not正确值



std :: vector< int> m_PointVectors;



该功能在以下情况下失败:

myclass obj;

obj.emplace-back(3, 4);

obj.emplace_back(5,6)

obj.emplace_back(7,8)

obj.emplace_back(3,6) )



size = 3



myclass obj2;

obj2.copy (obj);



// aobve函数

obj.InsertAt(3,& obj2);

大小应该是6 //但它的nt wrking

// inssert不接受类指针



this is not wortking can u tell any other soulution.not giving correct value

std::vector<int> m_PointVectors;

the function fails in following scenario :
myclass obj;
obj.emplace-back(3,4);
obj.emplace_back(5,6)
obj.emplace_back(7,8)
obj.emplace_back(3,6)

size = 3

myclass obj2;
obj2.copy(obj);

//aobve function
obj.InsertAt(3, &obj2);
size should be 6 //but its nt wrking
//inssert not accepting class pointer

推荐答案

因为(正如你在注释) m_PointVectors std :: vector< int> ,其插入方法不能接受 myclass 对象作为参数(除非你指定正确的转换运算符)。

你应该发布 myclass 获得更好帮助的实际代码。
Since (as you stated in the comments) m_PointVectors is a std::vector<int>, its insert method cannot accept a myclass object as parameter (well, unless you specify the proper conversion operator).
You should probably post the myclass actual code to get better help.


我用以下逻辑解决了我自己:

< br $> b $ b

m_ points .insert(m_points .begin()+ ptNum,point2Array-> m_points .begin(),point2Array-> m_points .end());
i solved my self with the below logic:


m_points .insert(m_points .begin() + ptNum, point2Array->m_points .begin(), point2Array->m_points .end());


这篇关于怀疑在向量c ++ inerst api的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆