The McLeodGaming forums were permanently closed on April 30th, 2020. You are currently viewing a read-only archive.
View unanswered posts | View active topics It is currently Fri May 15, 2020 5:51 am



 [ 4 posts ] 
C++ Noob with a question 
Author Message
User avatar

Joined: Mon Oct 24, 2011 10:03 am
Posts: 13
Gender: Anime Girl
So I got a couple C++ books for Christmas, and I've been learning for a couple of days. I've gotten a few original programs compiled and whatnot, but I was wondering once I get into projects concerning graphics like sprites and I want to release the programs to other people, would I have to make some sort of built-in compiler? Or is it as simple as saving as a different filetype?
Also in C++- although objects were defined, I'm not confident in my understanding of what it means? Can some one help me out with understanding objs?


Fri Dec 30, 2011 8:10 pm
User avatar

Joined: Tue Jun 16, 2009 2:48 am
Posts: 834
Location: Australia.
Gender: Male
Skype: snoble7
dunno about the first part but i can try with your oop question

i also found objects very tricky to understand, you're not alone

you create objects via CLASSES, which you can think of the blueprint for objects - when you create an object from this class, it will have all the traits you defined in the initial class

within this class you define METHODS, which are basically functions but they will be enclosed within your objects - this sounds complicated, but it is easier when shown in practice

ill use some pseudocode to make all clear

lets make a class for a bicycle

within this class, we'll define things like speed, gear, etc, and give methods to change these

Code:
class Bicycle {

speed = 0;
gear = 1;


this means any objects we create from the BICYCLE class will have a "speed" variable which is set to 0 and a "gear" variable which is set to "1"

next we can define some methods - this is where things get interesting

Code:
method changeGear(newGear) {
     gear = newGear;

method changeSpeed(newSpeed) {
     speed = newSpeed;


what these two methods do is give us the ability to change the SPEED and GEAR of our bike object via calling the objects method with the new value in place of newGear/newSpeed - again, when you see this in practice it seems simpler

so now that we've got this class we can create an object from it as such (this is pseudocode, not c++!!!!)

Code:
bike1 = new Bicycle();


now we have a bicycle called "bike1"

"bike1" has a speed of 0, a gear of 1, and two methods to change it as such

to speed "bike1" up to say 5, we would use:

Code:
bike1.changeSpeed(5);


to change "bike1" to gear 3, we would use:

Code:
bike1.changeGear(3);


this object only changes things within itself...BUT objects can be used to change any part of your program as well as other objects, assuming you do it correctly

this is a very basic overview and there is much more to it, and this is NOT c++ code

ask questions if necessary


Sun Jan 01, 2012 6:13 pm
User avatar

Joined: Sat Aug 16, 2008 8:38 am
Posts: 6670
Location: Darkest Antartica
Country: Pakistan (pk)
Gender: Male
Skype: Thaiberium
Currently Playing: The Game
So what about constructors? Those are important for classes.

_________________
Image


Sun Jan 01, 2012 7:06 pm
User avatar

Joined: Tue Jun 16, 2009 2:48 am
Posts: 834
Location: Australia.
Gender: Male
Skype: snoble7
those were basics feel free to elaborate further


Sun Jan 01, 2012 8:49 pm
Display posts from previous:  Sort by  
 [ 4 posts ] 

Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

cron
Powered by phpBB® Forum Software © phpBB Group
Designed by ST Software for PTF.