Advertisement

What's wrong?

Started by December 29, 2014 05:16 PM
17 comments, last by Dalphin 10 years, 1 month ago

I have to do a programming excercise for university.

I've done most of it, but I get some error and I can't figure out what's
wrong and how to solve it.

I hope you can understand it, because as I said it's for university and
that's why I have to do it in my native language.

Why do other people need to decipher a foreign language to debug your intentionally contrived homework, that you are supposed to do yourself to presumably learn those things by doing them?huh.png

At http://en.cppreference.com/w/cpp/language you can read almost anything about C++, happy learning.wink.png

I have to do a programming excercise for university.

I've done most of it, but I get some error and I can't figure out what's
wrong and how to solve it.

I hope you can understand it, because as I said it's for university and
that's why I have to do it in my native language.

Why do other people need to decipher a foreign language to debug your intentionally contrived homework, that you are supposed to do yourself to presumably learn those things by doing them?huh.png

At http://en.cppreference.com/w/cpp/language you can read almost anything about C++, happy learning.wink.png

Ho Ho Ho wait a second there.

I have done the most work and I don't ask anyone to do my homework and I will do the last part myself too,

but if you just read the post, like the people, who are likely to help me, do, you will see that I do not ask anyone to do this for me.

I only get an error massage, which I can't solve and I ask people to help me with that.

You know why I ask this question on gamedev.net and not just on a C++ forum? Because if

I ask something on another forum there are a lot of people, that do not read the question carefully and

say just the same thing as you say. But here one gamedev.net it seemed like those people do not exist.

Because every time I ask a question, how stupid are begginish it may be, I always get a nice answer.

It seemed like people on this forum are different, but unfortunately it seems like this isn't the case for everyone.

(But luckily the most people are nice and are trying to help, thanks to you vogues.)

And @wintertime: Please just read the post carefully next time and if you don't want to help,

just do not say anything, because it's superfluous

Advertisement

I was able to make it work here:

http://codepad.org/O9Bci0Mf

But I'm not sure if instantiating Venster rather than VensterMetTitel was actually the idea which then makes my code defeat the purpose.
I haven't been able to make Diego's solution work though.

Thanks for the big effort. But I get one question now: If you use virtual inheritance, do

you need to call the constructor of both the direct and the indirect base class in the constructor of the

inherited class?

Well I sort of discovered it while doing it and it didn't compile otherwise but if the base class had a default constructor it's probably going to be called implicitly. I'm actually going to try this and get back here with the results. Hang on.

results

http://codepad.org/zmJmQ59P

It turns out you can omit either Rechthoek or Venster explicitly if they have default constructors, however it's better to call the explicit constructor with h,b as if you don't set the member variables you'll get undefined behaviour.

Hint: it always helps to add a few cout's like I did in the constructors when you have complex hierarchies like this so you can see in what order they are called if at all.

Okey thanks

haha wow did it again

^

|

|

|

|

Advertisement

Thanks for the big effort. But I get one question now: If you use virtual inheritance, do

you need to call the constructor of both the direct and the indirect base class in the constructor of the

inherited class?

Well I sort of discovered it while doing it and it didn't compile otherwise but if the base class had a default constructor it's probably going to be called implicitly. I'm actually going to try this and get back here with the results. Hang on.





results

http://codepad.org/zmJmQ59P



It turns out you can omit either Rechthoek or Venster explicitly if they have default constructors, however it's better to call the explicit constructor with h,b as if you don't set the member variables you'll get undefined behaviour.

Hint: it always helps to add a few cout's like I did in the constructors when you have complex hierarchies like this so you can see in what order they are called if at all.

Guys, that's what the link I shared says. It even explains why this issue happens:

You need to call A's constructor explicitly here

D(int i) : A(i), B(i), C(i) {

virtual base classes are special in that they are initialized by the most derived class and not by any intermediate base classes that inherits from the virtual base. Which of the potential multiple initializers would the correct choice for initializing the one base?

If the most derived class being constructed does not list it in its member initalization list then the virtual base class is initialized with its default constructor which must exist and be accessible.

"A" class being equivalent to Rochthoek, "B" being Venster, "C" being FlexRochthoek and "D" being VensterMetTitel.

In your case, you're not doing multiple inheritance but are doing virtual inheritance, so that's equivalent to:


D(int i) : A(i), B(i) {

or


VensterMetTitel(int h, int b) : Rochthoek(h,b), Venster(h,b) {

I have to do a programming excercise for university.

I've done most of it, but I get some error and I can't figure out what's
wrong and how to solve it.

I hope you can understand it, because as I said it's for university and
that's why I have to do it in my native language.

Why do other people need to decipher a foreign language to debug your intentionally contrived homework, that you are supposed to do yourself to presumably learn those things by doing them?huh.png

At http://en.cppreference.com/w/cpp/language you can read almost anything about C++, happy learning.wink.png

Ho Ho Ho wait a second there.

I have done the most work and I don't ask anyone to do my homework and I will do the last part myself too,

but if you just read the post, like the people, who are likely to help me, do, you will see that I do not ask anyone to do this for me.

I only get an error massage, which I can't solve and I ask people to help me with that.

You know why I ask this question on gamedev.net and not just on a C++ forum? Because if

I ask something on another forum there are a lot of people, that do not read the question carefully and

say just the same thing as you say. But here one gamedev.net it seemed like those people do not exist.

Because every time I ask a question, how stupid are begginish it may be, I always get a nice answer.

It seemed like people on this forum are different, but unfortunately it seems like this isn't the case for everyone.

(But luckily the most people are nice and are trying to help, thanks to you vogues.)

And @wintertime: Please just read the post carefully next time and if you don't want to help,

just do not say anything, because it's superfluous

You assume wrongly. I had read the whole question, looked through your code, which you did not even check for the parameter names before posting, and read all answers and saw you already got told the solution about the need for the constructor call for all virtual base classes without default constructor.

You seem to not know, but the policy here is to only hint sparsely for homework and not spoil the answers.

@wintertime I didn't meant to get my whole homework done by someone else, because

how can I ever become a game developer if other people have to do things for me and

excuse me if I asked further after someone gave me the solution, but while I'm not perfect I didn't

understand it completely and I didn't saw through that that answer was the solution, but I see now and I understand

what was wrong and that's what it's all about.

Excuse me too that I assumed it wrong, but what you wrote sounded quiete offensive and not-interested at all.

I hope everything is solved now.

Again thanks too all that helped me or tried to help!!

This topic is closed to new replies.

Advertisement