Jump to content


 


Register a free account to unlock additional features at BleepingComputer.com
Welcome to BleepingComputer, a free community where people like yourself come together to discuss and learn how to use their computers. Using the site is easy and fun. As a guest, you can browse and view the various discussions in the forums, but can not create a new topic or reply to an existing one unless you are logged in. Other benefits of registering an account are subscribing to topics and forums, creating a blog, and having no ads shown anywhere on the site.


Click here to Register a free account now! or read our Welcome Guide to learn how to use this site.

Photo

Classes?


  • Please log in to reply
5 replies to this topic

#1 IKnew

IKnew

  • Members
  • 46 posts
  • OFFLINE
  •  
  • Local time:04:55 PM

Posted 16 April 2007 - 10:59 PM

I am using "C++ All-In-One Desk references for Dummies" to learn C++, i am having problems finding out when to use classes and what they are for... theres many examples of classes in the book but it seems that its lot easier to do the same thing as what the examples are doing using just functions then the class...

BC AdBot (Login to Remove)

 


#2 groovicus

groovicus

  • Security Colleague
  • 9,963 posts
  • OFFLINE
  •  
  • Gender:Male
  • Location:Centerville, SD
  • Local time:02:55 PM

Posted 17 April 2007 - 07:30 AM

Classes are what contain those functions, and you can not use the functions unless you are using the class. Classes make up libraries, and can be thought of as specialized units. Classes are a concept associated with object oriented programming....

#3 IKnew

IKnew
  • Topic Starter

  • Members
  • 46 posts
  • OFFLINE
  •  
  • Local time:04:55 PM

Posted 17 April 2007 - 05:35 PM

isnt functions like...

int myfunction()
{
return 5;
}

int main()
{
cout<<myfunction()<<endl;
return 0;
}


while a class is like

class myclass
{
public:
int getvalue() {return itsvalue;}
void setvalue(int value) {itsvalue=value;}

private:
int itsvalue;
};


i know that a class is made up of functions but i also know that functions doesn't have to be in a class, i dont get when i should use the classes...

Edited by IKnew, 17 April 2007 - 05:37 PM.


#4 groovicus

groovicus

  • Security Colleague
  • 9,963 posts
  • OFFLINE
  •  
  • Gender:Male
  • Location:Centerville, SD
  • Local time:02:55 PM

Posted 17 April 2007 - 05:58 PM

Let's start out with this question.....If functions are not in a class, then where are they?

The concept of using classes is so that you can have chunks of code that are independent of each other, but can be put together in such a way that they make a whole program. Simple programs only consist of one class. All classes are objects, or rather, all objects are created from classes. An object is an instance of a class, and all Objects have fundamental methods, or functions, associated with them, which is maybe why you are under the impression that functions don't have to be in classes.

One uses multiple classes when a program needs to perform multiple, unrelated functions. Take this web page as a loose example. One class would be to display the stats at the bottom of the page. One class would generate the list of forums. One class generates the text boxes where you make responses. One class interacts with the database. None of these classes know anything about each other. A final class assembles all of the information and displays it as a web-page. In reality, there are dozens and dozens of classes that make up a complex program.

Does that explain it any better? Understanding classes, objects, and instances is incredibly confusing at first.... at least it was for me.

#5 IKnew

IKnew
  • Topic Starter

  • Members
  • 46 posts
  • OFFLINE
  •  
  • Local time:04:55 PM

Posted 17 April 2007 - 06:21 PM

thank you, i sort of understand it now, though my head hurts... :thumbsup:

Edited by IKnew, 17 April 2007 - 06:22 PM.


#6 groovicus

groovicus

  • Security Colleague
  • 9,963 posts
  • OFFLINE
  •  
  • Gender:Male
  • Location:Centerville, SD
  • Local time:02:55 PM

Posted 17 April 2007 - 06:28 PM

Here, try this for making your head hurt:
http://www.c3.lanl.gov/mega-math/workbk/in...ty/inhotel.html

:thumbsup:




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users