Does anybody know if there is any way to pass instantiated objects of classes to functions either via pointer or reference, or some other way? I'm really scratching my head on this one.
Here you have the 3 basic ways to pass an object to a function. The first way passes the pointer by value and then we dereference the pointer. In otherwords, it is like just passing the address of our object instance so we do not make a copy of it.
The second way actually passes it by reference, so we do not have to use -> we can use it like any normal object, except the object you are referring to is o. No copy is made.
The last one is passed by value. This means an entire copy of o is made and then passed to the function. This is very inefficient and not recommended unless you are passing primitive types.
After that there is also const correctness. Because you may want to pass your object in such a way that the function can only read your object's data, not modify it. But that can be for another topic, it can be a bit tricky to get right.
I've tried all 3 methods but no matter what I do I can't get the class to recognize the object. The problem lies in line 28 in the following:
Here is the main.cpp code:
Thoughts?
Does Ball have a Brick ?
What does Ball.h look like?
Danger! Using reference member variables is a somewhat advanced usage. Typically you would do so using a constructor, not a public "initialize" method. A smart pointer might be a better option. They could come in handy for C allocations as well, such as your Allegro 5 objects. Of course, you need to crawl before you walk. I recommend that you put this project on hold and get a grip on the C++ language. Start a new code file to experiment with. Simple, short programs to just figure out the syntax. C++ is one of the most difficult languages to learn and write for. It seriously takes years just to figure out how little you know. If you try to take on too much at once you'll run into wall after wall and burn out. Take it slow. It's exhausting to just think of how to help you at this point...