• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
C++: Inline ctors not init'ing data members?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

C++: Inline ctors not init'ing data members?


  • Subject: C++: Inline ctors not init'ing data members?
  • From: Dan Caugherty <email@hidden>
  • Date: Mon, 15 Jun 2009 15:35:43 -0400

Hey all --

I found something strange this past week, and I hope there's a simple explanation for it that will leave me feeling terribly stupid.

I'm working on a project that has a class something like the (just a little) contrived one below:

//
// haberdasher.h
//
namespace using std;

class haberdasher {
   public:
      haberdasher() : hat_sizes_(), customers_() {}
      ~haberdasher() {}
      // ...
      void add_customer(const string & name) { customers_.push_back(name); }
      const string & get_last_customer() const { return customers_.back(); }
   private:
      map<string, unsigned int> hat_sizes_;
      vector<string> customers_;
};

After a call to add_customer(), the call to get_last_customer() will retrieve a faulty reference (in this case, the data area of the string will contain a char pointer equal to 0x0). Adding and accessing items in the map behaves similarly.

Defining the constructor in haberdasher.cpp (making it non-inline) resolves the issue.

Why should this be the case? 

(Again, I'm probably missing something obvious here...)

Thx in advance,
-- Dan C.
 _______________________________________________
Do not post admin requests to the list. They will be ignored.
Xcode-users mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden

  • Follow-Ups:
    • Re: C++: Inline ctors not init'ing data members?
      • From: "William H. Schultz" <email@hidden>
  • Prev by Date: Re: [Answered] Creating new Xcode projects into Subversion (Was: Xcode and Subversion)
  • Next by Date: Re: C++: Inline ctors not init'ing data members?
  • Previous by thread: Re: Xcode's Display Name in the Dock
  • Next by thread: Re: C++: Inline ctors not init'ing data members?
  • Index(es):
    • Date
    • Thread