Friday, September 10, 2010 09:50:43Login · Register
 

    Challenge Activity
09:22:09 - l0gan_l135
     - Completed real [2]
07:42:10 - l0gan_l135
     - Completed real [3]
05:55:17 - aspen_23
     - Completed recon [1]
02:27:21 - GemaRastem
     - Completed basic [2]
02:26:21 - GemaRastem
     - Completed basic [1]
02:21:00 - GemaRastem
     - Completed recon [3]
01:55:39 - GemaRastem
     - Completed recon [2]
01:43:45 - GemaRastem
     - Completed recon [1]
01:31:59 - veerendragautam2009
     - Completed decrypt [3]
01:26:45 - veerendragautam2009
     - Completed decrypt [2]
01:25:16 - veerendragautam2009
     - Completed decrypt [1]
12:31:00 - veerendragautam2009
     - Completed basic [1]
12:26:04 - veerendragautam2009
     - Completed recon [6]
11:13:29 - veerendragautam2009
     - Completed recon [3]
10:59:23 - veerendragautam2009
     - Completed recon [1]
09:30:05 - sirEgghead
     - Completed real [4]
 

    Scoreboard Top 20
UserPoints
Abhineet4795   
auditorsec4795   
ne0114795   
Null Set4795   
blandyuk4780   
bluechill4750   
Teddy4730   
TurboBorland4475   
Qwexotic4460   
tiiger11114205   
preet4180   
LiquidFusi0n4175   
OnlyHuman4125   
samthg4110   
satishek3900   
pilchdragon3660   
Override3655   
chronic123640   
sirEgghead3625   
dash803590   
 

    Login
Username

Password



Not a member yet?
Click here to register.

Forgotten your password?
Request a new one here.
 

    Users Online
· Guests Online: 7

· Members Online: 0

· Members on IRC: 9
Xires, TurboBorland, ryan1918, Polynomial, louve, LK, IFailStuff, epoch_qwert, connection

· Bots Online: 0

· Total Members: 1,491
· Newest Member: elostaz3omda
 

 

 

 

    Top 10 Forum Posters
UserPosts
bluechill918   
Qwexotic699   
cruizrisner487   
Null Set363   
TurboBorland335   
madf0x311   
Stormc1nd3r308   
auditorsec302   
Override238   
jakecrepinsek235   
 

    Affiliates
 

C++ Tutorial 3: Switches and Classes
     
[u]C++ Tutorials: Switches and Classes[/u

In this tutorial we will be covering classes. We have talked about classes before but never really learned how they work. A switch statement though is different and we haven't talked about them yet.

A class looks like this

Code

class SomeName
{
public:
     //public functions
private:
    //private functions
}





the statement:

Code

class SomeName





defines a class with the name: SomeName

Code

public:





is used for methods which are accessible outside of the class. This does not mean you can't call a public function or variable from within the class though. You can do that.

Code

private:





is used for functions accessible inside of the class. These are used internally and if tried to be used outside of the class will create a compile error.

Inheritance:

Classes have a unique feature. Here is an example demonstrating this:

Code

class InheritanceClass
{
public:
    void method();
}

class OtherClass : public InheritanceClass
{
public:
    void someOtherMethod();
}

InheritanceClass::method();
OtherClass::method();
OtherClass::someOtherMethod();





Notice that method(); was not defined in OtherClass but was defined in InheritanceClass. Inheriting means that if you have one class and it inherits from another you will be able to access those in that other class. To make a class inherit from another you use colon ( : ) public ClassName, replacing class name with the class you want this class to inherit from.

Now for the switch statement. A switch statement is similar to an if statement but more efficient when used well and looks much nicer.

Code

int i = 2;

switch(i)
{
case 0:
    //Do something when i  is 0
    break;
case 1:
    //Do something when i is 1
    break;
case 2:
   //Do something when i is 2
    break;
}





Notice another new thing:

break;

Break is used to break out of loops, and switches. If you do not have a break in the switch statement it will continue and check if that variable (in this case i) is equal to case :

That concludes this tutorial. In the Next one we will discuss While, and For loops.
 
Comments
 
#1 | Pingu on 03/27/2010 10:03
nice tutorial.
maybe you should add the "default"-case in the switch example
#2 | Torrment on 04/03/2010 05:05
very informative thanks
 
 
Post Comment
 
Please Login to Post a Comment.
 
 
Ratings
 
Rating is available to Members only.

Please login or register to vote.

Awesome! Awesome! 50% [1 Vote]
Very Good Very Good 50% [1 Vote]
Good Good 0% [No Votes]
Average Average 0% [No Votes]
Poor Poor 0% [No Votes]