Re: Can't compile this code

From: Karl Heinz Buchegger (kbuchegg_at_gascad.at)
Date: 11/25/04


Date: Thu, 25 Nov 2004 13:10:52 +0100

Morten Gulbrandsen wrote:
>
> #include <iostream>
>
> using namespace std;
>
> class Cat
> {
> private:
> int weight;
> int age;
>
> void DoMeow()
> {
> cout << "Meow\n";
> }
>
> public:
> Cat::Cat(int theWeight, int theAge)
> {
> weight = weight;
> age = theAge;
> }
>
> void Meow(int howManyTimes)
> {
> for (int i = 1; i < howManyTimes; i++)
> {
> DoMeow();
> }
> }
>
> };
>
> int main()
> {
> Cat frisky = new Cat(5,3); // cannot convert from 'class Cat *' 'class
> Cat'
> frisky.Meow(3);
>
> return 0;
> }
>
> ===
>
> Only one error left,
>
> What can I do ?

Read a book?
Seriously: You should read a book. I haven't analyzed your
first 2 error messages (since somebody else already did it),
but this error is a trivial one (and the next one that is
waiting in your code is also trivial, *if you know the
basics*). If you are not able to see the problem there is
only one conclusion: You are trying to learn C++ in an
unsystematic way. Believe me: This is boud to fail!
C++ is much to complex to be learned that way. You will end
up with lots of knowledge holes and in the end know a little
bit about everything, but not enough for solid programming.

-- 
Karl Heinz Buchegger
kbuchegg@gascad.at


Relevant Pages

  • Re: Classes
    ... I see that I am falling in the case sensitive trap of ... >> int getAge(); ... It is class Cat, not Class Cat. ... > number of errors reported by the compiler increases at some points during ...
    (microsoft.public.vc.language)
  • Re: Cant compile this code
    ... int weight; ... > | void DoMeow() ...
    (alt.comp.lang.learn.c-cpp)
  • Cant compile this code
    ... int weight; ... void DoMeow() ... Cat::Cat(int theWeight, int theAge) ...
    (alt.comp.lang.learn.c-cpp)