How push_back and emplace_back methods working with class, that havent copy constructor

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

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! =)
1) emplace_* was added only in C++11.
2) MyVector.emplace_back ( TempClass ); calls copy constructor.
3) If you did not delete copy constructor explicitely, compiler will generate one for you anyway.

Show class declaration, or better create a minimum compiling snippet where your problem can be reproduced (or at least post error messages)
MiiNiPaa, thx to u for answer! Useful info about C++11, didnt knew that!
I dont see any reason to post my code here, coz it big. And i havent any error problems.
My task is: find, how i can force std::vector CREATE new element, without using copying smthing.
MyVector.emplace_back(); //should work, but FAIL again! This is what is doing it. Requires C++11 though. No other way to force a new element to be created in vector.

And you cannot store anyhing in standard containers which does not have copy or nothrow move constructor. Because standard containers move and copy elements around.
In fact most of the standard library relies on copy or move constructors.

Can I ask, how did you delete default copy constructor in your class?
Ah, nice qiestion xD
I didnt deleted it, i have super-mega-big class with tons of pointers, so this fact force me to write my own copy constructor, it is hard, and i dont realy need it (in my code). So, i thought, it can work without any copying operations. But, looks like, i was wrong...
super-mega-big class
Smells fishy and prime target for refactoring
with tons of pointers
This is why you do not use raw pointers. Simply by replacing raw owning pinters with unique_ptr, you (a) have copy constructor removed, so it will generate an error instead of doing wrong thing and (b) have a properly working move constructor.

Also you should always adhere to the rule of 3/rule of 5. Even if you do not use something directly this does not mean that there isn't something which tries to silently use those functions.
Topic archived. No new replies allowed.