how to use an Array of a class? (modified)
-
The last time you posted this question, someone (I believe it was PJ Arends) asked what the value of 'i' is when it crashes. Umm, what is that value? You have an array of 10 pointers. You only show the first item in the array being used. Something is happening elsewhere or code you haven't shown. What line of code does the "crash" occur? Mark
"If you can dodge a wrench, you can dodge a ball."
At any value of i (e.g. i=0) it crashes on initialization of the element (before Save() function)
-
MohammadAmiry wrote:
Clips[i]=new CClipSaver;
Shouldn't this be:
Clips[i] = new CClipSaver();
MohammadAmiry wrote:
Clips[i]->Save();. But it crashes!
Have you stepped into the
Step()
method to figure out why? If, however,Clips[i]
isNULL
, you should not be calling theSave()
method.
"Approved Workmen Are Not Ashamed" - 2 Timothy 2:15
"Judge not by the eye but by the heart." - Native American Proverb
Oh yes!
Clips[i] = new CClipSaver();
is correct and it was a missprint (although I have tried both)! It throws an Access Violation error!
-
MohammadAmiry wrote:
Clips[i]=new CClipSaver;
Shouldn't this be:
Clips[i] = new CClipSaver();
MohammadAmiry wrote:
Clips[i]->Save();. But it crashes!
Have you stepped into the
Step()
method to figure out why? If, however,Clips[i]
isNULL
, you should not be calling theSave()
method.
"Approved Workmen Are Not Ashamed" - 2 Timothy 2:15
"Judge not by the eye but by the heart." - Native American Proverb
Hey DavidCrow, I noticed that too. What's the difference between those? I always "thought" that without parenthesis, the default constructor gets called. I always use the parenthesis so I never bothered to look it up :) Thanks! Mark
"If you can dodge a wrench, you can dodge a ball."
-
Oh yes!
Clips[i] = new CClipSaver();
is correct and it was a missprint (although I have tried both)! It throws an Access Violation error!
MohammadAmiry wrote:
It throws an Access Violation error!
Where????? Throw us a bone here :)
"If you can dodge a wrench, you can dodge a ball."
-
Hi I have a class named CClipSaver and I want to create an array of this class. I do this as follows:
CClipSaver* Clips[10]; . int i=0; Clips[i]=new CClipSaver; Clips[i]->Save(); .
But it crashes! Note: When I do not use array (i.e.
CClipSaver * Clip; Clip=new ClipSaver(); Clip**->**Save();
) everything works fine. How should I declare and use the array?I think the best advice people can give you is: use your debugger, it will save you hours of hassle. If you never used it, it's time you start to ;). Put some breakpoints (by pressing F9) in your program where you want to check relevant information and start the debugger (press F5). If you handle it well, it will give you much more information than we could give you (because we just have a very short code snippet).
Cédric Moonen Software developer
Charting control [v1.1] -
Hey DavidCrow, I noticed that too. What's the difference between those? I always "thought" that without parenthesis, the default constructor gets called. I always use the parenthesis so I never bothered to look it up :) Thanks! Mark
"If you can dodge a wrench, you can dodge a ball."
Mark Salsbery wrote:
What's the difference between those?
For non-integral types, there is none. For integral types (e.g.,
int
,char
), it amounts to whether initialization occurs or not.Mark Salsbery wrote:
I always use the parenthesis so I never bothered to look it up
Same here.
"Approved Workmen Are Not Ashamed" - 2 Timothy 2:15
"Judge not by the eye but by the heart." - Native American Proverb
-
Mark Salsbery wrote:
What's the difference between those?
For non-integral types, there is none. For integral types (e.g.,
int
,char
), it amounts to whether initialization occurs or not.Mark Salsbery wrote:
I always use the parenthesis so I never bothered to look it up
Same here.
"Approved Workmen Are Not Ashamed" - 2 Timothy 2:15
"Judge not by the eye but by the heart." - Native American Proverb
Cool. Thanks for saving me the trouble of looking it up myself :)
"If you can dodge a wrench, you can dodge a ball."
-
Hi I have a class named CClipSaver and I want to create an array of this class. I do this as follows:
CClipSaver* Clips[10]; . int i=0; Clips[i]=new CClipSaver; Clips[i]->Save(); .
But it crashes! Note: When I do not use array (i.e.
CClipSaver * Clip; Clip=new ClipSaver(); Clip**->**Save();
) everything works fine. How should I declare and use the array?In fact I use this code inside an MFC dll. When I put F9 on the line and press F5 to load the file that uses the dll, it disables the breakpoint expressing that the breakpoint is disabled because it is at the beginning of the program!! I now used it in an MFC exe, surprisingly, NO ERROR occurs!! :confused::^)
-
I think the best advice people can give you is: use your debugger, it will save you hours of hassle. If you never used it, it's time you start to ;). Put some breakpoints (by pressing F9) in your program where you want to check relevant information and start the debugger (press F5). If you handle it well, it will give you much more information than we could give you (because we just have a very short code snippet).
Cédric Moonen Software developer
Charting control [v1.1] -
Hi I have a class named CClipSaver and I want to create an array of this class. I do this as follows:
CClipSaver* Clips[10]; . int i=0; Clips[i]=new CClipSaver; Clips[i]->Save(); .
But it crashes! Note: When I do not use array (i.e.
CClipSaver * Clip; Clip=new ClipSaver(); Clip**->**Save();
) everything works fine. How should I declare and use the array?OH I finally figured out!!! The dll had to be called from a vb6 application (the hell with that!) X| In declarations, there was a missing ByVal statement, which caused address value of i to be sent instead of its value. Thanks all you folks for your attention which helped me figure this out, by checking other possibilities! :-D :rose: