i'm using Dev C++ Ver. 4.0
I can't get a class to work
whats wrong with this?Code:class animal { int wieght; int fleas; string name; }; { {40, 10, "JohnDo"} };
I can do structures... Whats the difference between the 2?
i'm using Dev C++ Ver. 4.0
I can't get a class to work
whats wrong with this?Code:class animal { int wieght; int fleas; string name; }; { {40, 10, "JohnDo"} };
I can do structures... Whats the difference between the 2?
This war, like the next war, is a war to end war.
What is this? You can't have an unnamed block at global scope, and it's not even a part of your class. If you want to make an object and assign values, try using a constructor. Also keep in mind that the default access of a class is private, so with your class definition you have no way of getting at the members.Code:{ {40, 10, "JohnDo"} };
It's better to not make your members public, but for now you don't have to worry about it.Code:#include <string> using namespace std; class animal { public: int wieght; int fleas; string name; animal(int w, int f, string n) { wieght = w; fleas = f; name = n; } }; int main() { animal my_animal(40, 10, "JohnDo"); };
*Cela*
To confusing... mind meltdown in 3...2...1....0.... KABOOOOOOOM
a little explanation.. cuz looking at that gives me headache!
No offense.. i just don't know what everything is..
This war, like the next war, is a war to end war.
>>i just don't know what everything is..
It's a simple concept, just open any book on C++ and look for "constructor" in the index. They can probably explain it better than I can.
*Cela*
PHP Code:
class ANIMAL //This is our ANIMAL Class Declaration
{
public: //This declares that the following Variables or Functions are public - there are also private and protected specifiers.
int a;
int b;
string c;
ANIMAL(); //Every class has a CONSTRUCTOR
~ANIMAL(); //Every class has a Deconstructor
//Here's where we declare functions contained within the class.
int AnimalType(int num);
}; //Make sure u have a ';' at the end of the bracket, in a class
//Here's where we DEFINE the class functions, including the contrutor and destructor
ANIMAL::ANIMAL(){ //Constructor Def
}
ANIMAL::~ANIMAL(){ //Destructor DEF
}
int ANIMAL::AnimalType(int num){ //AnimalType Fxn DEF
...
}
My Avatar says: "Stay in School"
Rocco is the Boy!
"SHUT YOUR LIPS..."
I see.... maybe C++ isn't for me.. cuz i still dont know what Animal::~animal is! its the :: throwing me off i think.. i have 2 c++ books, Primer C++, and Al stevens Teach yourself C++, they have different tings. and now this is also different...... am i getting mixed messages?
This war, like the next war, is a war to end war.
Classes are SOOOOOOOO simple, really.
Get a different book at the library or something and "READ" the chapters on classes. It requires alot more explanation than can be given on a board, but it is simple as HEck.
My Avatar says: "Stay in School"
Rocco is the Boy!
"SHUT YOUR LIPS..."
Originally posted by Blizzarddog
I see.... maybe C++ isn't for me.. cuz i still dont know what Animal::~animal is! its the :: throwing me off i think.. i have 2 c++ books, Primer C++, and Al stevens Teach yourself C++, they have different tings. and now this is also different...... am i getting mixed messages?
Animal::~Animal(){}
is the equivalent to:
the :: is just the scope resolution operator.Code:class Animal { public: ~Animal(){} // this line };
If you want a better book, try C++ the complete reference by Herbert Schildt, the fourth edition.