Doctor Mario 1987 - c++ object by references as argument

Hi all I’m new here !
I’m just done with a course in University LAVAL - QC…sorry for my bad english :slight_smile: !

here is the mail I sent to my prof and 2 colleges…no answer yet…

Any help would be GREEEEAT !

complete code : https://github.com/nokkkkkk/BiskWar.git

----------------------------------------------------------------QUESTION----------------------------------------

I just finished the IFT-3100 course with you and it was great!

Being a fan (with my spouse and my 2 children) of Doctor Mario 1987,
:slight_smile:

I decided to code a more dynamic remake in OpenFrameWork / c ++.

I started a few days ago …

https://github.com/nokkkkkk/BiskWar.git // I put public for
you.

I have a little problem passing an object by reference …
I did research for and even ask for resource people but without success
for the time being. If you don’t have time for this kind of
question … We ignore without problem :slight_smile: :)!

The object (Game.cpp) comes from a class of type Coplien … that is to say
including a pointer vector to a pure virtual class producing
dynamic allocation (polymorphism.)

The Main branch of git compiles and works BEFORE adding … I have
add the PascalDebug branch (for a person named pascal who
wanted to help me :))

The PascalDebug branch contains the mini changes made for
pass the instantiated Game … object “game_on” in the application.cpp.

I don’t know why but then I receive an error to the effect that
<Block *> is not known anymore…

I can do a little hack that only passes my array
(m_etat_table) but I would like to understand WHY to the big WHY
! :slight_smile:

If but you want to take a detour in my code to change the evil
of correction time:) … I would be VERY HAPPY! … Especially not to
not understanding frustrates me a bit I think;)

Big “T” thank you for your time and have a nice day!

-Guillaume Vallerand-

Thanks in advance !

Salut!

I took a glance at the code and while some old-schoolers might not agree, and while there is certainly a “computer science” explanation of what is happening with the pointer/reference, i recommend modifying the pointers to use std::shared/unique_ptr, moving to std::make_shared/unique<>() instead of new. This will make the code safer, will probable remove your problem, and (in the context of long-lived objects) will not affect performance.

1 Like

THANKS ! for the reply ! I actually did a refacto where the vector is controlled in his own class(Game.cpp)…Solved my problem…but still not able to understand the error in that particular case…

Thanks for your time !!

-Guillaume-

I also had a look at the code but couldnt really work out what the issue is.

When I face things like this I usually make a new project which is just for testing/troubleshooting. I will make classes and code as basic and as simple as possible.

For example I wont copy complete classes over from the main project, I add just as few lines as possible until I can re-create the issue and then usually its a lot easier to troubleshoot and debug.

If you can make a minimal example like that which exhibits the issue I would be happy to take a look as I am sure others would be as well.

HI Thanks and good Idea !

I had a couple of chat and the error is related to my include and cyclic redondant…

I also did a refacto wich help a lot.

Thanks a lot Guys !!

Hey for what its worth I like @burton 's response. Any C-style pointers that are variables (objects) in these classes can have issues with std::vector (and other containers) if they move around in memory. ofNode is a great example of this, and there are posts in the forum about it. If you use unique pointers, don’t forget to std::move() them into a std::vector, or use emplace_back to construct the object inside the vector, as the objects they point to can’t be copied.

1 Like

Thanks I’ll definitively have a look at that !

here a little screenshot ! :slight_smile:

So what would u say the issue was? I am just interested as I like finding out about the details of C++

Cool looking app too btw