Post: [C++] Simple Classes
03-16-2011, 06:41 PM #1
Girby2K11
☮ ☯ ☢ ✔ ➝
(adsbygoogle = window.adsbygoogle || []).push({}); Guys, im learning classes in my Game programming C++ book.

and it is quite tricky but im getting there im now always practicing making programs like this one.
Some times i use ----> private: also im starting static

    #include <iostream>
#include <cstdlib>


using namespace std;

// Classes Done by Curtis.

class object
{
public:
int object1;
void objects();
};


void object:Gaspbjects()
{
if (object1 > 100 )
{
cout << "Negative, number bigger than 100\n";
exit(1);
}

if (object1 < 0)
{
cout << "Negative, you have entered a number smaller than 0\n";
}

else
{
cout << "You have entered " << object1;
}
}


int main()
{


cout << " Classes!\n\n";

object obj;

cin >> obj.object1;

obj.objects();

return 0;
}


Has any got any tips for me. I would like to no if anyone had problems with it but now understands perfect classes.
03-16-2011, 07:03 PM #2
Originally posted by Girby2K11 View Post
Guys, im learning classes in my Game programming C++ book.

and it is quite tricky but im getting there im now always practicing making programs like this one.
Some times i use ----> private: also im starting static

    #include <iostream>
#include <cstdlib>


using namespace std;

// Classes Done by Curtis.

class object
{
public:
int object1;
void objects();
};


void object:Gaspbjects()
{
if (object1 > 100 )
{
cout << "Negative, number bigger than 100\n";
exit(1);
}

if (object1 < 0)
{
cout << "Negative, you have entered a number smaller than 0\n";
}

else
{
cout << "You have entered " << object1;
}
}


int main()
{


cout << " Classes!\n\n";

object obj;

cin >> obj.object1;

obj.objects();

return 0;
}


Has any got any tips for me. I would like to no if anyone had problems with it but now understands perfect classes.


please tell me you have learnt data structures before attempting classes? and you do understand pointers and whatnot?
03-16-2011, 08:52 PM #3
Girby2K11
☮ ☯ ☢ ✔ ➝
Originally posted by TheUberFail View Post
please tell me you have learnt data structures before attempting classes? and you do understand pointers and whatnot?


i have learnt pointers, What do you mean Data Structures?
03-16-2011, 09:30 PM #4
Originally posted by Girby2K11 View Post
i have learnt pointers, What do you mean Data Structures?


    
struct person{

unsigned byte age;
string name;

};

person TheUberFail;

TheUberFail.age = 17;
TheUberFail.name= "TheUberFail";

person *pointer;

pointer->age = 9999;
pointer->name = "God";

The following user thanked TheUberFail for this useful post:

kiwimoosical
03-16-2011, 09:35 PM #5
kiwimoosical
Bounty hunter
struct = data structure. I have one for weird int types. Lemme find it.
03-16-2011, 10:08 PM #6
Ritztro
I am a Game Developer
Originally posted by Girby2K11 View Post
Guys, im learning classes in my Game programming C++ book.

and it is quite tricky but im getting there im now always practicing making programs like this one.
Some times i use ----> private: also im starting static

    #include <iostream>
#include <cstdlib>


using namespace std;

// Classes Done by Curtis.

class object
{
public:
int object1;
void objects();
};


void object:Gaspbjects()
{
if (object1 > 100 )
{
cout << "Negative, number bigger than 100\n";
exit(1);
}

if (object1 < 0)
{
cout << "Negative, you have entered a number smaller than 0\n";
}

else
{
cout << "You have entered " << object1;
}
}


int main()
{


cout << " Classes!\n\n";

object obj;

cin >> obj.object1;

obj.objects();

return 0;
}


Has any got any tips for me. I would like to no if anyone had problems with it but now understands perfect classes.


Well the whole point of classes is to simulate actual objects. So I would not recommend using classes explicitly if it is easier not to. But if you do have something that needs multiple vars and functions that need to be grouped, then use classes. But like TheUberFail said, learn pointers and structs first as they are very useful. Pointers especially when you get into things that require large amounts of data.
03-16-2011, 10:17 PM #7
kiwimoosical
Bounty hunter
Originally posted by Dutch View Post
Well the whole point of classes is to simulate actual objects. So I would not recommend using classes explicitly if it is easier not to. But if you do have something that needs multiple vars and functions that need to be grouped, then use classes. But like TheUberFail said, learn pointers and structs first as they are very useful. Pointers especially when you get into things that require large amounts of data.


Wrong. A class is the blue-print of an object reference (instance of a class). Not a simulation of an object, a class just contains all of the members that are going to be entered into the memory register. When you call the new keyword it loads the class' members into the register and then calls the constructor.
03-16-2011, 10:20 PM #8
Ritztro
I am a Game Developer
Originally posted by kiwimoosical View Post
Wrong. A class is the blue-print of an object reference (instance of a class). Not a simulation of an object, a class just contains all of the members that are going to be entered into the memory register. When you call the new keyword it loads the class' members into the register and then calls the constructor.


Well I was just trying to explain how it is used, not all the technical stuff lol.
03-16-2011, 10:42 PM #9
kiwimoosical
Bounty hunter
Originally posted by Dutch View Post
Well I was just trying to explain how it is used, not all the technical stuff lol.


But you still explained false information. Just say, it's used to give the design for an object. Easy as dat.
03-17-2011, 03:54 PM #10
Girby2K11
☮ ☯ ☢ ✔ ➝
Originally posted by TheUberFail View Post
    
struct person{

unsigned byte age;
string name;

};

person TheUberFail;

TheUberFail.age = 17;
TheUberFail.name= "TheUberFail";

person *pointer;

pointer->age = 9999;
pointer->name = "God";


but isn't data structurs - struct the same as classes like with the

struct girb
{
int i;

}

except that struct doesnt use public: and private:?

---------- Post added at 03:54 PM ---------- Previous post was at 03:53 PM ----------

Originally posted by kiwimoosical View Post
Wrong. A class is the blue-print of an object reference (instance of a class). Not a simulation of an object, a class just contains all of the members that are going to be entered into the memory register. When you call the new keyword it loads the class' members into the register and then calls the constructor.


entered memory? isn't that just like pointers?

Copyright © 2024, NextGenUpdate.
All Rights Reserved.

Gray NextGenUpdate Logo