I wrote a member function:
MA::MA(int ID, int num, const char first[20], const char last[20], int* arr, bool r)
{
BA(ID, num, first, last, arr);
this->research = r;
}
r and research are boolean.
he threw me out while running and told me it's because of the second line in the function... why?
From what you've posted we can see almost nothing.
We need to know what MA is.
We have no idea what BA is or does.
We can't see the context in which this apparent constructor was called.
We need to see something we can test, something we can compile without having to assume so much.
However, with the assumption that this compiled, none here could theorize why a bool would refuse assignment to a bool at runtime. If this compiled the problem would have to be something about "this" instead of something about the two bools involved.
Yet, we just can't tell.
Also, when posting code, place the code between code tags, like this:
If "this" was 0x64, that is not likely a valid pointer on anything other than an odd embedded processor.
We still have nothing to help you. We need more context.
However, the information from your error (which you should usually include when asking a question about such an error) indicates my theory is correct, the calling context is invalid and somehow you don't actually have a valid instance running.
@ag12, is this some super secret source code you can't post?
Seriously, you MUST be able to recognize just how little information this includes. I just don't get that part. What is so secret that you can't post the code impacting the execution of your application?
Ok, enough rant.
There's only one thing I can propose as a valid theory.
We have the likelihood that "this" is not valid. This bit of code in your post of 4:04 pm shows it is allocated on the stack. At least that's something to work with, though it's tiny.
Assuming the code is operating correctly up to this point, when MA is constructed, then we must assume that "this" inside the MA constructor would be valid.
We must test that theory. BEFORE the call to BA, use debugging tools to view the "this" pointer's value (it should not be 0x64).
Now, call BA.
Did "this" change? That's my theory.
Something in BA is writing over the stack's memory, corrupting "this", and making anything that otherwise simply can't fail to fail.
It is likely BA is processing "arr" in such a way that there's a buffer overrun. Since I can't see BA, I have no idea.
If we test "this" before BA is called and it is invalid even then, we have entirely different problems, likely nothing to do with this bit of code.
Not much else to propose while blind out here.
It just so happens that 0x64 is 100 decimal, and that happens to be one of the values (repeated) in your arr3 array.
ag12, first, something that applies to both your original post and your latest one: You're calling the base class constructors wrong. To properly initialize the base class object, it has to be done the way I did it in my previous example. Currently, your call to Student on line 3 is just making a temporary student object. You're not actually modifying the base object of your current object.
Second, line 9: while (arr[i]). What do you expect this to do? Your original arr3 array contains no 0s! So this is going out of bounds, and is most likely where your crash originates.
@Ganado, that was quick. I'd go so far as to say it's more that just likely, or most likely, it's most certainly going to do something wrong, very wrong.
@ag12, Ganado has the goods, and I'm glad the theory I was pursuing was essentially on point, but as you can see there was no way we could see the problem without the BA constructor.
What is the reason of using plain arrays and C-strings?
Could you use std::vector and std::string in their place?
That would simplify the code and avoid some errors "for free".