Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

Need help making classes

This topic is 5092 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I have been trying to learn how to make a windows class. as in the code that makes your windows into a class. I know the basic of a class Firts question what does the Constructor and destructor do. What is there perpose? Second what is public, private, and protected? EX. class cname { public: public things go into here cname(); //Constructor ~cname(); //destruct private : cname(); //Constructor ~cname(); //destruct

Share this post


Link to post
Share on other sites
Advertisement
Firts question what does the Constructor and destructor do. What is there perpose?

Constructor : what you call when you create an instance of the class - here all the initialisation
Destructor : what is called every time the instance loses scope

Second what is public, private, and protected?

public : can be reached from outside the class (example : getX() or setX() functions)

private : cant be reached from outside the class - if int a is a private member you cant X.a = 5; from your main function. You'd have to call a public method of X which can set a to 5 (X.setA(5))

protected : same as private but your vars can also be reached from subclasses

owh, and you usually dont want to make your constructor private, in most cases it wouldn't be usefull



The ever vigilant...


[edited by - MonkeyInBlack on June 10, 2004 8:32:32 PM]

Share this post


Link to post
Share on other sites
MonkeyInBlack Thanks for the help.

I have been reading books and tutorials on c++ classes.
I just dont get everything about them.

I understand functions and structers and the like.


I just dont get something about classes and there uses.

I know it has to do with reuseing the same code and incapsulateing the code to work by it self idividuly.

What I am trying to do is make a window class. but I cnt figure out were to start from.

any help would help

Thanks

[edited by - kingpinzs on June 10, 2004 12:05:34 AM]

Share this post


Link to post
Share on other sites
You might want to start with something easier (Like something that''s all up in your head). Why don''t you make a, say, addition class or a basic stack. Something like that so you can figure out how classes work and why you should use them etc.

Share this post


Link to post
Share on other sites
you probably wont "get" the point of OOP right away. just work with a little bit, follow the rules you know (encapsulation), and eventually you will realize the whole point...

think of an OOP program as a well-oiled machine. the machine is made up of many different parts. if a part to the machine gets old or breaks, no problem. just take out that part and slap in a new one. do you get the point? in OOP, you must encapsulate everything as well as possible, so each class has no external dependencies. that way, when something bad happends or you want to upgrade - you change change that one class, and no other classes will care, their doing their own thing too. now imagine if your machine was one giant hunk of metal welded all togeather - what happends when one of the parts breaks or needs to be changed? your screwed, it effects everything else, and you have to make changes to every part.. think if a car was a giant hunk of metal.. you wouldnt want to have to put in a new engine just to fix the wiper''s.....


hope that made a lil sence im new to this whole programming deal too, and i didnt reall "get" OOP untill working on my 3rd game

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!