• 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
Re: C++: Inline ctors not init'ing data members?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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


  • Subject: Re: C++: Inline ctors not init'ing data members?
  • From: "William H. Schultz" <email@hidden>
  • Date: Mon, 15 Jun 2009 14:16:12 -0700

This might be a stretch, but if this code is in a library/framework while the code using it is in a client of that library/framework, then you could potentially have issues with dead code stripping or inlines not being exported. Anything that forces the class to be instantiated in and exported from the library/framework would potentially be a fix to the issue.


------------------------------- Hank Schultz Cedrus Corporation http://www.cedrus.com/


On Jun 15, 2009, at 12:35 PM, Dan Caugherty wrote:

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

_______________________________________________ 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
References: 
 >C++: Inline ctors not init'ing data members? (From: Dan Caugherty <email@hidden>)

  • Prev by Date: C++: Inline ctors not init'ing data members?
  • Next by Date: Xcode unit tests are never executed
  • Previous by thread: C++: Inline ctors not init'ing data members?
  • Next by thread: Re: Re: C++: inline ctors not init'ing data members?
  • Index(es):
    • Date
    • Thread