[color=blue][color=green]
> > Hi,
> >
> > Comming from Java, it seems that prototype declarations are like[/color][/color]
abstract[color=blue][color=green]
> > methods. I have not read classes in C++ yet, but prototype declarations[/color]
> are[color=green]
> > a strange concept. Any comments appreciated.
> >
> >
> > WD
> >[/color]
>
> Prototypes are not like abstract methods in any way I can see.[/color]
I was referring to the fact that abstract methods in Java do not have a
method body, just like a prototype declaration in C++.
[color=blue]
> Prototypes are just a way to tell the compiler what a function or method
> signature is without actually defining the function or method.[/color]
Right. But why you need to do this? reading on...
[color=blue]
> Java has a completely different compilation model from C++. In Java the
> compiler looks up a method signature when a method is called. It can do[/color]
this[color=blue]
> because Java defines rules on where a method can be defined.[/color]
But in more detail, hows does the compiler in Java look up a method that is
called? I know the use of the import statement in Java allows us to avoid
fully qualifying data fields and methods of a class that is imported. This
is becuase it puts the file in a local folder? and thats how it knows where
to find it??
[color=blue]
> C++ on the other hand uses a model of separate compilation. This requires[/color]
the[color=blue]
> programmer to provide a declaration of any method before any call of that
> method.[/color]
Separate from what? I know the linker theory does in here somewhere as well.
More detail perhaps?
[color=blue]
> void f(); // prototype
>
> int main()
> {
> f();
> }
>
> void f()
> {
> }
>
> Without seeing the prototype the compiler would not know anything about f
> when it compiled main, since its definitions occurs after main. Without[/color]
the[color=blue]
> prototype you would get an 'undefined f' error message.[/color]
Nice example.
Regards,
WD
---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (
http://www.grisoft.com).
Version: 6.0.504 / Virus Database: 302 - Release Date: 24/07/2003