Re: Can't compile this code
From: Chris \( Val \) (chrisval_at_bigpond.com.au)
Date: 11/25/04
- Next message: Karl Heinz Buchegger: "Re: Can't compile this code"
- Previous message: Morten Gulbrandsen: "Re: Can't compile this code"
- In reply to: Morten Gulbrandsen: "Re: Can't compile this code"
- Next in thread: Francis Glassborow: "Re: Can't compile this code"
- Reply: Francis Glassborow: "Re: Can't compile this code"
- Reply: Morten Gulbrandsen: "Re: Can't compile this code *****SOLVED****"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Thu, 25 Nov 2004 22:18:49 +1100
"Morten Gulbrandsen" <Morten.Gulbrandsen@rwth-aachen.de> wrote in message
news:30ls7cF30n7etU1@uni-berlin.de...
| #include <iostream>
[snip]
I thought I gave you all the clues you needed :-)
| int main()
| {
| Cat frisky = new Cat(5,3); // cannot convert from 'class Cat *' 'class
Here is your first problem.
The operator 'new', returns a pointer to allocated
memory, if it was successful, otherwise it throws
an 'std::bad_alloc()' exception, in it's default
mode of operation.
So if 'new' returns a pointer to memory for a 'Cat'
object, then we need to store that returned pointer
in a 'Cat*' object type, therefore, what we need to
do is this:
Cat* PtrToCat = new Cat( 5, 3 );
Since we are now working with a pointer to a 'Cat' object,
the rules have changed slightly, in the way that we access
it's internal parts. In this case, we need to use a very
different member access operator '->' instead, thus we can
now complete our task with:
PtrToCat -> Meow( 3 );
| Cat'
| frisky.Meow(3);
|
| return 0;
| }
|
|
| ===
|
| Only one error left,
|
| What can I do ?
[snip]
You could purchase some good beginner books.
Do you have any ?
Perhaps we can offer some suggestions, if you
indicate your level of experience(s) ?
Cheers.
Chris Val
- Next message: Karl Heinz Buchegger: "Re: Can't compile this code"
- Previous message: Morten Gulbrandsen: "Re: Can't compile this code"
- In reply to: Morten Gulbrandsen: "Re: Can't compile this code"
- Next in thread: Francis Glassborow: "Re: Can't compile this code"
- Reply: Francis Glassborow: "Re: Can't compile this code"
- Reply: Morten Gulbrandsen: "Re: Can't compile this code *****SOLVED****"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|
|