Objective C++ class question


i've been messing objc c++ quite time now, , building framework unify 2 languages.

have c++ class contains objc class this:

code:
class sfmutablestring{ public: 	nsmutablestring *_str; 	 	 	sfmutablestring(){_str = [nsmutablestring new];} 	~sfmutablestring(){ 		[_str release]; 		nslog(@"str deallocating...."); 	}  	sfmutablestring(const char* astring){ 		[_str setstring:[nsmutablestring stringwithcstring:astring encoding:nsutf8stringencoding]]; 	} 	sfmutablestring(const sfmutablestring& other){ 		_str = [nsmutablestring stringwithstring:other._str]; 	} 	sfmutablestring(nsstring* astring){ 		_str = [nsmutablestring stringwithstring:astring]; 	} 	void getstring(const char* astr){ 		[_str setstring:[nsmutablestring stringwithcstring:astr encoding:nsutf8stringencoding]]; 	} 	 	sfmutablestring operator=(sfmutablestring& other){ 		[_str setstring:other._str];  		return *this; 	} 	sfmutablestring operator=(const nsstring *otherstring){ 		[_str setstring:[nsmutablestring stringwithstring:otherstring]]; 		return *this; 	} 	 };
and have simple main():
code:
int main (int argc, const char * argv[]) { 	sfmutablestring str = @"hello world!"; 	nslog(str._str); 	return 0;	 } 
the code compiles ok, on runtime, error:
code:
[session started @ 2007-08-27 10:19:08 +0300.] 2007-08-27 10:19:08.245 foundation tool 1[1100] *** _nsautoreleasenopool(): object 0x605050 of class nscfstring autoreleased no pool in place - leaking 2007-08-27 10:19:08.245 foundation tool 1[1100] hello world! 2007-08-27 10:19:08.245 foundation tool 1[1100] str deallocating....  foundation tool 1 has exited status 0.
i tried using autorelease pool, errors double deallocation... ideas on why happens , can do?

edit: tried using autorelease pool, had remove [release str] command deallocation method of class. somehow, don't feel way supposed done. mean, if implement class (without release command on deallocation, leaving job done autorelease pool) on cocoa program, won't memory leaks?
 

1. sfmutablestring(const char* astring) constructor asking trouble. think crash.

2. assignment operators return object *this. highly unusual thing do, because means copy constructor called every assignment. return reference object, not object itself.
 


Forums Macs Mac Programming


  • iPhone
  • Mac OS & System Software
  • iPad
  • Apple Watch
  • Notebooks
  • iTunes
  • Apple ID
  • iCloud
  • Desktop Computers
  • Apple Music
  • Professional Applications
  • iPod
  • iWork
  • Apple TV
  • iLife
  • Wireless

Comments

Popular posts from this blog

New iMac here - LOVING the Mighty Mouse

Mini-DVI to DVI-I?

How to best wire an entire house mac...(I want a touch screen in my bathroom)