Created
October 9, 2014 15:26
-
-
Save ashwin/adffb1bd939ba8a74003 to your computer and use it in GitHub Desktop.
Sample code to demonstrate emplace_back operation of vector
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Sample code to demonstrate emplace_back operation of vector | |
#include <iostream> | |
#include <vector> | |
struct Creature | |
{ | |
Creature() : is_mammal_(false), age_(0), population_(0) | |
{ | |
std::cout << "Default constructor called\n"; | |
} | |
Creature(bool is_mammal, int age, int population) | |
: is_mammal_(is_mammal), age_(age), population_(population) | |
{ | |
std::cout << "3-arg constructor called\n"; | |
} | |
bool is_mammal_; | |
int age_; | |
int population_; | |
}; | |
typedef std::vector<Creature> CreatureVec; | |
int main() | |
{ | |
CreatureVec cv; | |
cv.emplace_back(true, 10, 9999); | |
cv.emplace_back(); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment