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-17-2011, 04:07 PM #11
kiwimoosical
Bounty hunter
Not at all, a pointer is just something that points to something in memory, whenever you assign, or really do anything in your code it is loaded into memory. Pointers can be used to find something that is at an allocated memory address or toset data at a memory address or various other things...
03-26-2011, 02:28 AM #12
3arc
Meow.
Originally posted by Girby2K11 View Post
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 ----------



entered memory? isn't that just like pointers?

Structs are similar to classes, except they are always public, and can only contain ivars, not methods, where classes can have both.
03-26-2011, 12:06 PM #13
Girby2K11
☮ ☯ ☢ ✔ ➝
Originally posted by 3arc View Post
Structs are similar to classes, except they are always public, and can only contain ivars, not methods, where classes can have both.


oh, well that just about sums it all Smile
03-26-2011, 12:08 PM #14
Look at all of you Happy . Give him a break , He's learning No

Copyright © 2024, NextGenUpdate.
All Rights Reserved.

Gray NextGenUpdate Logo