bad code?
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
#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
You don''t have any curly braces { } after main, and no
semi-colon after the last brace of your class.
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
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.,
// 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.
#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
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement