If this is your first visit, be sure to
check out the FAQ by clicking the
link above. You may have to register
before you can post: click the register link above to proceed. To start viewing messages,
select the forum that you want to visit from the selection below.

Need help fixing an error

I ran the program and now lines 38, 92, 105, 108, 129, 138-140, 156-160, and 183 have these lime green colored blocks next to them and the error opens this crtexe.cpp file and highlights line number 555 in there:

Re: Need help fixing an error

It took literally less than a second for the debugger to point out that test is an invalid pointer. You need to learn to use your debugger. You can't program without it.

Look at this code.

Code:

Student::test = studentArray;
test = 0;

First, why are you using the scope resolution operator. That's not needed, and even misleading here.
test = studentArray would be more appropriate, although why you're not just initialing test instead of using studentArray isn't clear.

Regardless, you allocate it, then immediately set the allocated pointer to zero.

Re: Need help fixing an error

Well sorry if i did a rookie mistake i am extremely new to programming like maybe less than a year experience. I have no idea what half of these errors even mean, and so i have trouble problem solving. What exactly do i need to change to make it work better. with the makeArray function I am trying to make an array with num elemets, and store it in test. I thought what i did was that exactly but turns out it isn't so what do i need to change?

Re: Need help fixing an error

Well like i said I am fairly new to programming, and what you said made little to no sense to me, luckily i figured it out on my own. Just because i do something wrong doesn't mean you have to be an *** about it. Maybe you could learn to notice someone didn't understand what you said and try rewording it. Lets hope to god you never go into IT and ACTUALLY have to help people.

Thanks for helping anyways i guess, i figured it out about 3 hours ago.

Re: Need help fixing an error

Originally Posted by fergis911

Well like i said I am fairly new to programming, and what you said made little to no sense to me, luckily i figured it out on my own.

So let's see your final results. You may think you fixed the problem, but with the code you had and the little experience you claimed, there is a good chance you really didn't fix the problem but only believed you fixed the problem.

When writing C++, you need to be 100% sure that the code is correct. There is a concept called undefined behaviour that occurs when the program seems to behave "correctly", but in reality is still wrong and can crash. Your code is not beginner code, as it deals with classes, dynamically allocated memory, etc. When you get to that stage, it is mandatory that you know exactly what you're doing, and as GCDEF stated, use the debugger.

Unless you are experienced in C++ such as GCDEF and others here, then the claim that you fixed the code can't really be trusted unless you show us how you addressed the problem.

Re: Need help fixing an error

Originally Posted by fergis911

Well like i said I am fairly new to programming, and what you said made little to no sense to me, luckily i figured it out on my own. Just because i do something wrong doesn't mean you have to be an *** about it. Maybe you could learn to notice someone didn't understand what you said and try rewording it. Lets hope to god you never go into IT and ACTUALLY have to help people.

There is no reason to react like this. Nobody blames you for making mistakes, but we do expect you try to make the most out of the advice you are getting from experienced C++ developers for free. If you don't understand part of that advice, then search the internet to see if you can find an explanation and if you still don't understand, indicate here exactly what you don't understand. If you are not willing to make an effort, you can't expect anyone else to make an effort for you.

GCDEF has indicated twice (in two different ways) that there is no reason to fully qualify your member variables. So, instead of writing "Student::num" and "Student::test", you can just write "num" and "test" in member functions of the Student class.

Which book are you using to learn C++? Based on the code you've posted, I would consider getting a better book to learn from. You almost never have to use new[] in C++ nowadays, using std::vector is better. A good book will teach you this from the very beginning.

Cheers, D Drmmr

Please put [code][/code] tags around your code to preserve indentation and make it more readable.

As long as man ascribes to himself what is merely a posibility, he will not work for the attainment of it. - P. D. Ouspensky

Re: Need help fixing an error

Originally Posted by fergis911

Well like i said I am fairly new to programming, and what you said made little to no sense to me, luckily i figured it out on my own. Just because i do something wrong doesn't mean you have to be an *** about it. Maybe you could learn to notice someone didn't understand what you said and try rewording it. Lets hope to god you never go into IT and ACTUALLY have to help people.

Thanks for helping anyways i guess, i figured it out about 3 hours ago.

I gave you advice. I even showed you how to write the function without all the extraneous stuff you put in there. You ignored what I said. I don't see how that makes me the bad guy here. If you don't understand what I said, ask for clarification, although honestly, if you didn't understand what I said, and from looking at your code, you should probably take a step back and work through a good tutorial book for a while. And no, that's not being obnoxious. That's just giving you good advice. This isn't a language where guessing gets you very far.

* The Perfect Platform for Game Developers: Android
Developing rich, high performance Android games from the ground up is a daunting task. Intel has provided Android developers with a number of tools that can be leveraged by Android game developers.

* The Best Reasons to Target Windows 8
Learn some of the best reasons why you should seriously consider bringing your Android mobile development expertise to bear on the Windows 8 platform.