Jichao Jichao - 4 months ago 40
Pascal Question

How to do OOP with Pascal?

I am learning OOP with the pascal programming language.After googling the Internet, I found the OOP -- The GNU Pascal Manaul.But when I typed in the source code of the example above and compile, gpc returns:

object.pas:13: error: unresolved forward declaration `Fooparent_Baz'

Why would gpc fail to compile its manaul's example.
PS:Checked typing, found mistakes in the code.

What does this function declarision mean,

function Baz (b, a, z: Char) = s: Str100; { not virtual }

I have never seen = xx before, and it seems that the pascal syntax do not have it.



That appears to be some nonstandard extension. The implementation of the function in question is:

function FooParent.Baz (b, a, z: Char) = s: Str100;
  WriteStr (s, 'FooParent.Baz (', b, ', ', a, ', ', z, ')')

Normally in Pascal, the name of the function is used as the function return variable, so the above function would be written like this:

function FooParent.Baz (b, a, z: Char): Str100;
  WriteStr (Baz, 'FooParent.Baz (', b, ', ', a, ', ', z, ')')

It appears that the = s syntax indicates that the return value of the function is stored in the variable s inside the function body. I'm not sure why that would need to be exposed in the object interface, though.