O
Olaf
Hi,
here the following test code
#include <iostream>
using namespace std;
struct Foo {
Foo() { cout << " Foo()\n"; }
~Foo() { cout << "~Foo()\n"; }
void set() const { cout << "Foo::set()\n"; }
};
struct Bar {
void set(const Foo& foo) const { foo.set(); }
};
int main() {
Bar b;
b.set( Foo() );
}
shows:
Foo()
Foo()
Foo::set()
~Foo()
~Foo()
Well, obviously the copy ctor from temporary is called. Can I avoid this
by using a different way?
Background: Foo can contain strings (should not be the problem) but also
function pointers and lists. About the last, I'm not sure about the copy
semantic. Any help here?
Thanks,
Olaf
here the following test code
#include <iostream>
using namespace std;
struct Foo {
Foo() { cout << " Foo()\n"; }
~Foo() { cout << "~Foo()\n"; }
void set() const { cout << "Foo::set()\n"; }
};
struct Bar {
void set(const Foo& foo) const { foo.set(); }
};
int main() {
Bar b;
b.set( Foo() );
}
shows:
Foo()
Foo()
Foo::set()
~Foo()
~Foo()
Well, obviously the copy ctor from temporary is called. Can I avoid this
by using a different way?
Background: Foo can contain strings (should not be the problem) but also
function pointers and lists. About the last, I'm not sure about the copy
semantic. Any help here?
Thanks,
Olaf