With fpc you can get "myfile.pas(77,47) Warning: Constructing a class "xxxx" with abstract methods"
I just would like to know why it is allowed to build classes with abstract methods. AFIK it is different from other compilers and it is a bit strange for me.
Mailing lists / fpc-pascal / 2008-01
Classes with abstract methods
15 messages · 6 people ·
- DDamien Gerard 6
- MMichael Van Canneyt 3
- JJonas Maebe 2
- PPeter Vreman 2
- GGraeme Geldenhuys 1
- MMatt Emson 1
Reply by email Subscribe to this list Your subscription
Read-only archive. Use j and k to move between messages.
Damien Gerard wrote 6 lines
Delphi gives exactly the same warning.
It is allowed to create such instances: as long as you don't call any of the abstract methods, there will be no problem.
Michael.
Michael Van Canneyt wrote 15 lines
I don't remember that.
It is allowed to create such instances: as long as you don't call any of the abstract methods, there will be no problem.
Is there a way to abort the compilation in this cases instead of a warning ?
Damien Gerard wrote 19 lines
D:\Temp>dcc32 unit1
Borland Delphi Version 15.0
Copyright (c) 1983,2002 Borland Software Corporation Unit1.pas(32) Warning: Constructing instance of 'TStrings' containing abstract method 'TStrings.Clear' Unit1.pas(32) Warning: Constructing instance of 'TStrings' containing abstract method 'TStrings.Delete' Unit1.pas(32) Warning: Constructing instance of 'TStrings' containing abstract method 'TStrings.Insert' Unit1.pas(32) Hint: Value assigned to 'T' never used Unit1.pas(36)
37 lines, 0.11 seconds, 475 bytes code, 8 bytes data.
Show quoted text 6 lines
Currently not.
Michael.
Michael Van Canneyt wrote> > Is there a way to abort the compilation in this cases instead of a warning ? Currently not.
If you want to be that strict, then use Interfaces instead of Abstract classes.
-
Regards,
- Graeme -
_______________________________________________
fpGUI - a cross-platform Free Pascal GUI toolkit
http://opensoft.homeip.net/fpgui/
D:\Temp>dcc32 unit1 Borland Delphi Version 15.0 Copyright (c) 1983,2002 Borland Software…
Michael Van Canneyt wrote 40 lines
Yes I trust you don't wory, just my mind is playing with me :)
Show quoted text 10 lines
Thanks
If you want to be that strict, then use Interfaces instead of Abstract classes. - -…
Graeme Geldenhuys wrote 9 lines
Indeed I should do this. Thanks
If you want to be that strict, then use Interfaces instead of Abstract classes. - -…
Graeme Geldenhuys wrote 8 lines
I always found (and still do in C#) that interfaces are good for forcing structure but bad for forcing good inheritance trees. The good thing about classes with abstract methods is that they form a point for inheritance. Interfaces - well, I regularly use interfaces to create a common structure, e.g. an API that will have both a webservice interface and a local interface. The common API is an interface in a separate assembly, used on both client and server to implement an identical API (client code can then link to either the local API or the webservice via a client that implements the same interface.) DotNet also makes reflection (RTTI) quite useful with interfaces too, but I digress. The point is that the webservice class, the client and the local API that the webservice wraps all implement the interface (the webservice usually just delegates responsibility to an internal instance), but none of them inherit from each other.
Show quoted text 7 lines
You can abort compilation in case of any warning with the -Sew option. The same goes for note or hint with -Sen or -Seh, but those are only usefull for compiler tests.
Peter
Peter Vreman wrote 10 lines
The problem with this mechanism is that if you have another warning which occurs first, that will stop your compilation, you'll never get to the abstract warning...
Michael.
Michael Van Canneyt wrote 23 lines
I agree.
May be a new option in a future release of fpc ? :) It would be nice to have a switch to do it.
Damien Gerard wrote 10 lines
There is already a feature request for the ability to turn off/on certain warnings in Mantis. Upgrading certain warnings (and hints/ notes) to errors is quite related. It should be quite doable for an outsider to implement this sort functionality, but until now no one has volunteered yet.
Jonas
Jonas Maebe wrote 19 lines
I see. I will see what I can do next month.
Show quoted text 14 lines
Upgrade a warning to error can already be done by editing (replace a W with an E) the errore.msg yourself and pass the modified errore.msg to the compiler with -Fr.
Peter
Peter Vreman wrote 9 lines
You can similarly downgrade a warning to a note or hint by changing the W with a N or H, but the problem is that you have to redo this for each release.
Jonas
