Post: Could someone explain?
05-30-2011, 06:48 PM #1
kjoshi
Do a barrel roll!
(adsbygoogle = window.adsbygoogle || []).push({}); Recently I've been learning C++ and I've come across classes. Now what I don't get is why you would use classes other than organizing variables and functions. I can do everything without classes and I really don't see a use for classes.

Could someone also explain what and why I would use constructors for? I'm really hating OOP because I don't see a purpose for things. :confused:

Anyway, thanks. Sad Awesome
(adsbygoogle = window.adsbygoogle || []).push({});
05-31-2011, 06:08 AM #2
Classes are for creating multiple sets of data with specific members and functions, for example. we have class called people, and it contains all the functions and variables of each person (in a game), and each functions are all the different ways a person can interact with the game engine, and all the variables are all data on each person. Without classes it would be impossible to create 400-500 different unique 'people' for an RPG game, this is just one example, another example is Microsoft Word, each 'New Document' is just creating a new instance of a blank page class, it has all the variables like footer/header settings, page data, ect.

There is just no way this is possible with plain functions and variables, well it is, but realistically 10x harder. Classes can be found everywhere in programming, Windows forms are classes, C# uses classes allot and Java too.

There are advanced concepts like Friendship and inheritance You must login or register to view this content. and Polymorphism You must login or register to view this content. that allow you to join classes together to share variables, and interact with each other differently.

The following user thanked Relevant for this useful post:

kiwimoosical
05-31-2011, 03:05 PM #3
kiwimoosical
Bounty hunter
Originally posted by Relevant View Post
Classes are for creating multiple sets of data with specific members and functions, for example. we have class called people, and it contains all the functions and variables of each person (in a game), and each functions are all the different ways a person can interact with the game engine, and all the variables are all data on each person. Without classes it would be impossible to create 400-500 different unique 'people' for an RPG game, this is just one example, another example is Microsoft Word, each 'New Document' is just creating a new instance of a blank page class, it has all the variables like footer/header settings, page data, ect.

There is just no way this is possible with plain functions and variables, well it is, but realistically 10x harder. Classes can be found everywhere in programming, Windows forms are classes, C# uses classes allot and Java too.

There are advanced concepts like Friendship and inheritance You must login or register to view this content. and Polymorphism You must login or register to view this content. that allow you to join classes together to share variables, and interact with each other differently.


Good explanation.
Another, more relevant reason to use classes is for re-usability. Say I have a class for handling money intake. Instead of rewriting the money intake system for 4 different applications. I could write it once, take the class file, put it in the project file for the new project, and use it like I did the first time. Another good example is a networking class, say I have a networking class that communicates between a computer and a server via TCP connection and I need it for more than one application. I could take the class and re-use it.
05-31-2011, 03:09 PM #4
Originally posted by kiwimoosical View Post
Good explanation.
Another, more relevant reason to use classes is for re-usability. Say I have a class for handling money intake. Instead of rewriting the money intake system for 4 different applications. I could write it once, take the class file, put it in the project file for the new project, and use it like I did the first time. Another good example is a networking class, say I have a networking class that communicates between a computer and a server via TCP connection and I need it for more than one application. I could take the class and re-use it.



Precisely, I love how also classes can be used to uniquely duplicate variables and functions, especially in networking, when your setting up your server, you dont want to set up each connection every single time, you want to create one main class of a connection, and keep making new instances of that class to open up new connection. Classes I have to say, are the most interesting aspect of programming.
05-31-2011, 03:13 PM #5
kiwimoosical
Bounty hunter
Originally posted by Relevant View Post
Precisely, I love how also classes can be used to uniquely duplicate variables and functions, especially in networking, when your setting up your server, you dont want to set up each connection every single time, you want to create one main class of a connection, and keep making new instances of that class to open up new connection. Classes I have to say, are the most interesting aspect of programming.


My favorite aspect of programming is reflection Winky Winky
Reflection: You must login or register to view this content.

Copyright © 2026, NextGenUpdate.
All Rights Reserved.

Gray NextGenUpdate Logo