Ich habe eine Klasse A
:Vermeiden Copykonstruktor während bevöl Mitglied Vektor
class A {
int value1;
int value2;
std::string text;
public:
A(int value1, int value2, std::string text)
: value1(value1), value2(value2), text(text) { }
};
und einige "Container" Klasse B
:
class B {
std::vector<A> objects;
...
public:
...
void addObject(A a) {
objects.push_back(a);
}
};
Und Code:
B b;
A a(2, 5, "test");
b.addObject(a);
//I no longer need a from now on
Mein Problem ist, wie man B::addObject(A a)
optimiert, um jedes Kopieren zu vermeiden. Was ich erreichen will, ist ein neues Objekt vom Typ A
zu B.objects
über B
Methode hinzufügen.
bezogen werden: https://stackoverflow.com/questions/2139224/how-to-pass- objects-to-functions-in-c – NathanOliver