Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- void getObjData( LargeObj& a )
- {
- a.reset() ;
- a.fillWithData() ;
- }
- int main()
- {
- LargeObj a ;
- getObjData( a ) ;
- }
- LargeObj getObjData()
- {
- LargeObj a ;
- a.fillWithData() ;
- return a ;
- }
- int main()
- {
- LargeObj a = getObjData() ;
- }
- typedef std::vector<HugeObj> LargeObj ;
- #include <iostream>
- class X
- {
- public:
- X() { std::cout << "X::X()" << std::endl; }
- X( X const & ) { std::cout << "X::X( X const & )" << std::endl; }
- X& operator=( X const & ) { std::cout << "X::operator=(X const &)" << std::endl; }
- };
- X f() {
- X tmp;
- return tmp;
- }
- int main() {
- X x = f();
- }
- LargeObj&& getObjData()
- {
- LargeObj a ;
- a.fillWithData() ;
- return a ;
- }
- int main()
- {
- LargeObj a = getObjData(); // calls the move constructor
- }
- LargeObj getObjData()
- {
- return LargeObj( fillsomehow() );
- }
- std::auto_ptr<LargeObj> getObjData()
- {
- std::auto_ptr<LargeObj> a(new LargeObj);
- a->fillWithData();
- return a;
- }
- int main()
- {
- std::auto_ptr<LargeObj> a(getObjData());
- }
- LargeObj::LargeObj() :
- m_member1(),
- m_member2(),
- ...
- {}
- LargeObj::LargeObj()
- {
- // (The body of fillWithData should ideally be re-written into
- // the initializer list...)
- fillWithData() ;
- }
- int main()
- {
- LargeObj a ;
- }
- class LargeObj : public std::vector<HugeObj> {
- // constructor that fills the object with data
- LargeObj() ;
- // ... other standard methods ...
- };
- LargeObj* getObjData()
- {
- LargeObj* ret = new LargeObj;
- ret->fillWithData() ;
- return ret;
- }
Add Comment
Please, Sign In to add comment