Re: Classes



try changing "Class" to "class"

"Missing identifier before 'Cat' " should make you look carefully at what's
in front of 'Cat'.


"Robby" <Robby@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
news:15874187-02B3-4914-B4A2-E13D3343D1C3@xxxxxxxxxxxxxxxx
> Hi there,
>
> I am reviewing some C++ examples and trying them out in Visual C++ console
> application. Here is an example straight out of the book I am reading. I
feel
> a little discouraged because I am getting a catastrophic amount of errors.
> Can someone please take look at this code fragment:
>
> #include <iostream>
> using namespace std;
>
> Class Cat
> {
> public:
> Cat(int initialAge);
> ~Cat();
> int getAge();
> void setAge(int Age);
> void Meow();
> private:
> int itsAge;
> };
>
> Cat::Cat(int initialAge)
> {
> itsAge = initialAge;
> }
>
> Cat::~Cat()
> {
> }
>
> int Cat::getAge()
> {
> return itsAge;
> }
>
> void Cat::setAge(int age)
> {
> itsAge = age;
> }
> void Cat::Meow()
> {
> cout << "Meow.\n";
> }
>
> int main()
> {
> cat Frisky(5);
> Frisky.Meow();
> cout << "Frisky is a cat who is ";
> cout << Frisky.getAge() << " years old.\n";
> Frisky.Meow();
> Frisky.setAge(7);
> cout << "Now Frisky is " ;
> cout << Frisky.getAge(); >> " years old. \n";
> return 0;
> }
>
> Here are some of the erros I am getting:
>
> c:\DATASOURCE_EXTRA\Programming\VC++CodeTesting\2_Classes\Class.cpp(5):
> error C2146: syntax error : missing ';' before identifier 'Cat'
>
> c:\DATASOURCE_EXTRA\Programming\VC++CodeTesting\2_Classes\Class.cpp(5):
> error C2501: 'Class' : missing storage-class or type specifiers
>
> c:\DATASOURCE_EXTRA\Programming\VC++CodeTesting\2_Classes\Class.cpp(5):
> error C2470: 'Cat' : looks like a function definition, but there is no
formal
> parameter list; skipping apparent body
>
> c:\DATASOURCE_EXTRA\Programming\VC++CodeTesting\2_Classes\Class.cpp(16):
> error C2653: 'Cat' : is not a class or namespace name
>
> and so forth...
>
> Anyone!
>
>
>
> --
> Best regards
> Robert


.



Relevant Pages