Advertisement

bad code?

Started by January 12, 2002 10:20 AM
14 comments, last by death_jester 22 years, 8 months ago
Whats wrong with my code.It looks fine to me. #include <iostream> int main() class Dog() { public: unsigned int itsAge; unsigned int itsWeight; Bark(); }
It's not "int main()". It should be like this:

#include <iostream>

void main() {

class Dog()
{
public:
unsigned int itsAge;
unsigned int itsWeight;
Bark();
};
}

Edited by - BioSquirrel on January 12, 2002 11:26:15 AM
Advertisement
You don''t have any curly braces { } after main, and no
semi-colon after the last brace of your class.
"I'm never alone, I'm alone all the time" - Glycerine-Bush"It starts with one thing" In The End-Linkin Park
Thanks.

First you have to put a semicolomn ";" after the last brace
in the class declararion.

Also do not forget to put "()" after "class Dog" because
then the compiler thinks that "Dog" is a function.

Then I would put the class declarartion in a header file.
After that I would put the definition og it´s class members in
its own source file.
After that include the header file in your project.

Class would now look like this and compile fine.


class Dog
{
public:
unsigned int itsAge;
unsigned int itsWeight;
Bark();
};



Friðrik Ásmundsson
what''s that? a class inside a main()? is that possible?
http://www.dualforcesolutions.comProfessional website designs and development, customized business systems, etc.,
Advertisement
what?do you mean no main in that code?
that was me.
// this is main.cpp

#include <iostream>
#include "Dog.h";
using namespace std;

int main()
{
Dog mydog;
mydog.Bark();
...
...
...
}


// now comes Dog.h

class Dog
{
public:
unsigned int itsAge;
unsigned int itsWeight;
Bark();
};

// and this is Dog.cpp

Dog::Dog()
{
itsAge = 5;
itsWeight = 10;
}

Dog::Bark()
{
cout << "VOFF\n";
}



Hope it helps, not tried though.
Friðrik Ásmundsson
Put the main loop below the dog class....Or the class above the main loop, whichever :D
delete this;

This topic is closed to new replies.

Advertisement