helixed
June 29th, 2008, 05:35 PM
Hello everybody,
I'm new to programming. I've been trying to teach myself C++, and so far everything seems to be working out very well. However, I've recently hit a snag while trying to compile the following code. I'm using XCode on a Mac as my compiler. Here's the code:
Header File "header.h":
#include <iostream.h>
class Cat
{
public:
Cat (int initialAge);
~Cat();
int GetAge() {return itsAge;}
void SetAge (int age) {itsAge = age;}
void Meow() {cout << "Meow.\n";}
private:
int itsAge;
};
Main program file "main.cpp":
//Demonstrates inline functions and inclusions of header files
//inclusion of header file
//This should include iostream.h and declare a class Cat
#include "header.h"
Cat::Cat(int initialAge)
{
itsAge = initialAge;
}
Cat::~Cat()
{
}
//Create a cat, set its age, have it meow, tell us its age, and then meow again
int main()
{
Cat.Frisky(5);
Frisky.Meow();
cout << "Frisky is a cat who is " << Frisky.GetAge() << " years old.\n";
Frisky.Meow();
Frisky.SetAge(7);
cout << "Now Frisky is ";
cout << Frisky.GetAge() << " years old.\n";
return 0;
}
The compiler returns two errors: one for the Cat.Frisky(5); line, and one for the Frisky.Meow(); line. The errors are:
error: expected unqualified-id before '.' token
and
error: 'Frisky' was not declared in this scope
I'm honestly not ever sure if this forum is where I should be posting this. If I have the wrong place, I would appreciate somebody pointing me in the right direction.
Thanks,
helixed
I'm new to programming. I've been trying to teach myself C++, and so far everything seems to be working out very well. However, I've recently hit a snag while trying to compile the following code. I'm using XCode on a Mac as my compiler. Here's the code:
Header File "header.h":
#include <iostream.h>
class Cat
{
public:
Cat (int initialAge);
~Cat();
int GetAge() {return itsAge;}
void SetAge (int age) {itsAge = age;}
void Meow() {cout << "Meow.\n";}
private:
int itsAge;
};
Main program file "main.cpp":
//Demonstrates inline functions and inclusions of header files
//inclusion of header file
//This should include iostream.h and declare a class Cat
#include "header.h"
Cat::Cat(int initialAge)
{
itsAge = initialAge;
}
Cat::~Cat()
{
}
//Create a cat, set its age, have it meow, tell us its age, and then meow again
int main()
{
Cat.Frisky(5);
Frisky.Meow();
cout << "Frisky is a cat who is " << Frisky.GetAge() << " years old.\n";
Frisky.Meow();
Frisky.SetAge(7);
cout << "Now Frisky is ";
cout << Frisky.GetAge() << " years old.\n";
return 0;
}
The compiler returns two errors: one for the Cat.Frisky(5); line, and one for the Frisky.Meow(); line. The errors are:
error: expected unqualified-id before '.' token
and
error: 'Frisky' was not declared in this scope
I'm honestly not ever sure if this forum is where I should be posting this. If I have the wrong place, I would appreciate somebody pointing me in the right direction.
Thanks,
helixed