Click here to Skip to main content
15,887,344 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i have insert function with class pointer :

the code is as follows :
C++
InsertAt(int ptNum, myclass *point2Array)
{
const MtPoint2d * PointArray = point2Array->GetData();
	if (PointArray == NULL) 
	{
		return; 
	}

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


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
Posted
Updated 26-Nov-15 2:23am
v5
Comments
CPallini 26-Nov-15 8:06am    
What does you mean exactly with 'it doesn't work'? How is m_PointVectors declared?
[no name] 26-Nov-15 8:22am    
std::vector<int> m_PointVectors;
Richard MacCutchan 26-Nov-15 8:19am    
What is the value of ptNum, and why does this function take point as its first parameter?
[no name] 26-Nov-15 8:22am    
point were to insert
[no name] 26-Nov-15 8:23am    
sry i chaged the function

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.
 
Share this answer
 
Comments
[no name] 26-Nov-15 8:34am    
std::vector<mtpoint2d> m_PointVectors; this is varaiable
[no name] 26-Nov-15 8:35am    
inline void
MtPoint2dVector::InsertAt(int ptNum, MtPoint2dVector *point2Array)
{


const MtPoint2d * PointArray = point2Array->GetData();
if (PointArray == NULL)
{
return;
}

m_PointVectors.insert(m_PointVectors.begin() + ptNum, *PointArray);
}
[no name] 26-Nov-15 8:36am    
the vector insert only accepting point
i solved my self with the below logic:


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

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900