Skip navigation

global alloc init declaration

686 Views 13 Replies Latest reply: Dec 14, 2012 3:37 AM by pheonixfire RSS
pheonixfire Calculating status...
Currently Being Moderated
Dec 6, 2012 3:20 AM

Is there anyway to do a global alloc init so all functions in a class can see it?

 

any help is appreciated

pheonixfire

xcode, OS X Mountain Lion (10.8.2)
  • etresoft Level 7 Level 7 (23,905 points)
    Currently Being Moderated
    Dec 6, 2012 4:13 AM (in response to pheonixfire)

    I would love to help if you would explain what you are talking about. Some examples of what you have now and what you would like to see would be nice.

  • etresoft Level 7 Level 7 (23,905 points)
    Currently Being Moderated
    Dec 6, 2012 7:39 PM (in response to pheonixfire)

    Each function has its own "scope"

  • Wayne Contello Level 6 Level 6 (12,650 points)
    Currently Being Moderated
    Dec 7, 2012 7:13 AM (in response to pheonixfire)

    etresoft alluded to this but automaic variables have scope only in the code segment (or function) in which they were allocated.

     

    for anotherFunction() to be able to access the something which is allocated in function() you should make the variable something a member of the class.  Otherwise something is created on the stack on entry to function, then removed from the stack on exist of function.

  • Wayne Contello Level 6 Level 6 (12,650 points)
    Currently Being Moderated
    Dec 8, 2012 4:46 AM (in response to pheonixfire)

    in the header file for your class add the variable as a member.

  • Wayne Contello Level 6 Level 6 (12,650 points)
    Currently Being Moderated
    Dec 9, 2012 6:23 AM (in response to pheonixfire)

    the error message is telling you that "addess" is an unknown type.

     

    I also think the assignment of destination to [[address alloc] init];  is in the wrong place.

  • Michael Superczynski Level 5 Level 5 (7,105 points)
    Currently Being Moderated
    Dec 9, 2012 6:26 AM (in response to pheonixfire)

    address *destination = [[address alloc]init];

     

    What is address?  It should be a class and thus would be designated as Address.

    You're allocating an instance (address) of the class Address.

     

    Thus, you should have the class Address declared somewhere.

  • Frank Caggiano Level 7 Level 7 (22,830 points)
    Currently Being Moderated
    Dec 10, 2012 7:41 AM (in response to pheonixfire)

    If you posted your code so we could see what you are trying to do it would help.

Actions

More Like This

  • Retrieving data ...

Bookmarked By (0)

Legend

  • This solved my question - 10 points
  • This helped me - 5 points
This site contains user submitted content, comments and opinions and is for informational purposes only. Apple disclaims any and all liability for the acts, omissions and conduct of any third parties in connection with or related to your use of the site. All postings and use of the content on this site are subject to the Apple Support Communities Terms of Use.