Hi all! First of all, sry for my bad english =(
I have the class MyClass. He havent copy constructor ( i have reasons to not do it ). I need to use this class in std::vector.
There is example
1 2 3 4 5 6 7 8 9 10 11 12 13
|
void MyFunction ( std::vector<MyClass> &MyVector )
{
//Now i need to add to my vector new element. I need to CREATE new element, not to copy!
//What did i tried
MyVector.push_back ( MyClass); //fail!
MyVector.push_back ( MyClass() ); //fail, coz i need copy constructor
MyVector.emplace_back(); //should work, but FAIL again!
//The only thing that working as i want
MyClass TempClass;
MyVector.emplace_back ( TempClass );
} //End
| |
So, this solution of problem is ugly and i think, that is wrong, so i have questions:
1) I think, when MyFunction will over, TempClass variable will be detroyed, so the memory in MyVector[0] will be marked as FREE. Is it true?
2) How i can CREATE in std::vector new element? Is it possible?
Please, just dont tell me that i MUST create copy constructor, it will be realy hard in my situation, this solution is the worthest for me now.
I using MS VS 2010 Express (so my C++ is 98, not 11).
Thank u for attetion! =)