Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

death_jester

bad code?

This topic is 5976 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Whats wrong with my code.It looks fine to me. #include <iostream> int main() class Dog() { public: unsigned int itsAge; unsigned int itsWeight; Bark(); }

Share this post


Link to post
Share on other sites
Advertisement
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

Share this post


Link to post
Share on other sites

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();
};



Share this post


Link to post
Share on other sites
Guest Anonymous Poster
what?do you mean no main in that code?

Share this post


Link to post
Share on other sites
// 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.

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!