I have the following code:
struct Entity {
Entity() {
std::cout << "[Entity] constructed\n";
}
~Entity() {
std::cout << "[Entity] destructed\n";
}
void Operation(void) {
std::cout << "[Entity] operation\n";
}
};
void funcCpy(Entity ent) {
ent.Operation();
}
int main() {
Entity e1;
funcCpy(e1);
}
This is the output:
[Entity] constructed
[Entity] operation
[Entity] destructed
[Entity] destructed
I expected my function to use the custom constructor, so the output would look like this:
[Entity] constructed
[Entity] operation
[Entity] constructed
[Entity] destructed
[Entity] destructed
Why does this happens? How could I use my custom constructor instead?
Thanks :)