CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4
  1. #1
    Join Date
    Dec 2008
    Posts
    3

    [RESOLVED] Pointer problem

    I have a problem with one of my pointers. I tried to define a pointer ptr to a user-defined class intmodn (which is made of two integers) by:

    intmodn *ptr;

    inside a class nmatrix. The instant the computer declares an nmatrix object, I get a segmentation fault coming from this. I assume (although I could be wrong) that the problem is that the compiler does not know how to allocate memory for an intmodn object, in which case, how does one do tell it?

  2. #2
    Join Date
    Dec 2008
    Posts
    3

    Re: Pointer problem

    oh btw im using g++

  3. #3
    Join Date
    Mar 2002
    Location
    St. Petersburg, Florida, USA
    Posts
    12,125

    Re: Pointer problem

    Post a minimal yet complete peice of code. This means the smallest possible piece of code that reproduces the exact rpoblem.
    TheCPUWizard is a registered trademark, all rights reserved. (If this post was helpful, please RATE it!)
    2008, 2009,2010
    In theory, there is no difference between theory and practice; in practice there is.

    * Join the fight, refuse to respond to posts that contain code outside of [code] ... [/code] tags. See here for instructions
    * How NOT to post a question here
    * Of course you read this carefully before you posted
    * Need homework help? Read this first

  4. #4
    Join Date
    Dec 2008
    Posts
    3

    Re: Pointer problem

    nvm I fixed it, I was being very dim. It was assigning my pointer a random garbage value rather than 0 and to avoid memory leaks a segment of my code has a delete in it, and that caused the segmentation fault I think. It for some reason didn't print anything I told it to, which is why I assumed it was a problem with the declaration. I fixed it by putting ptr=0; at the beginning of all my constructors (I am definitively a noob in the world of programming).

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured