Classes won't compile

Hey guys, i was wondering why Dev-C++ won't compile the following code:
(P.S. This is coming out of a C++ Learning book, and it still won't compile)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
/*
Name: Classes Demo
Copyright: n/a
Date/Time: 9/8/10
Description: simple class manipulation

#include <iostream>
#include <cstdlib>
#include <cstdio>
using namespace std;

class Cat 
{
      public:
            void Meow();
            int GetAge();
            void SetAge(int age);
      private:
            int itsAge;
}

void Cat::Meow()
{
   cout << "Meow.\n";
}
int Cat::GetAge()
{
  return itsAge;
}
void Cat::SetAge(int age)
{
    itsAge = age;
}

int main(int nNumberofArgs, char* pszArgs[])
{
    Cat Frisky;
    Frisky.Meow();
    Frisky.SetAge(5);
    cout << "Frisky is a cat who is " << Frisky.GetAge() << " years old.";
    Frisky.Meow();
    
    system("PAUSE");
    return 0;
} */

Thanks for the help
I believe this will compile:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
/*
Name: Classes Demo
Copyright: n/a
Date/Time: 9/8/10
Description: simple class manipulation
*/

#include <iostream>
#include <cstdlib>
#include <cstdio>
using namespace std;

class Cat 
{
      public:
            void Meow();
            int GetAge();
            void SetAge(int age);
      private:
            int itsAge;
};

void Cat::Meow()
{
   cout << "Meow.\n";
}
int Cat::GetAge()
{
  return itsAge;
}
void Cat::SetAge(int age)
{
    itsAge = age;
}

int main(int nNumberofArgs, char* pszArgs[])
{
    Cat Frisky;
    Frisky.Meow();
    Frisky.SetAge(5);
    cout << "Frisky is a cat who is " << Frisky.GetAge() << " years old.";
    Frisky.Meow();
    
    system("PAUSE");
    return 0;
}
Last edited on
Don't comment everything out when you are posting code
You are missing a semicolon on line 20
And get a newer/better IDE Dev-C++ is old http://www.cplusplus.com/forum/articles/7263/
Well uncommenting the code would probably help a bit...you are also missing a ';' after your class definition.
Ehm, are you compiling it with the comment blocks around it? lol
Last edited on
Sweet! Thanks guys... i think classes might help un-scary the thought of building a blackjack game bare.
Don't comment everything out when you are posting code


I was always confused why people would go out of there way to do this. It seems very strange.

But I've seen several people do it so they must all have some kind of similar thinking or something.
When I was studying programming, one of my classmates was having serious troubles with his program. When he asked me for help, I leaned over his screen and saw all of his code in comments.
"Well, it compiles much faster, that way", he said.
dev c++ it's open source download the patches.
Topic archived. No new replies allowed.