|
-
December 21st, 2008, 02:32 PM
#1
[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?
-
December 21st, 2008, 02:35 PM
#2
-
December 21st, 2008, 02:48 PM
#3
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
-
December 21st, 2008, 03:12 PM
#4
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|