Files |  Tutorials |  Articles |  Links |  Home |  Team |  Forum |  Wiki |  Impressum

Aktuelle Zeit: Di Apr 23, 2024 19:30

Foren-Übersicht » English » English Programming Forum
Unbeantwortete Themen | Aktive Themen



Ein neues Thema erstellen Auf das Thema antworten  [ 18 Beiträge ]  Gehe zu Seite 1, 2  Nächste
Autor Nachricht
 Betreff des Beitrags: C++ Class Operator in Pascal
BeitragVerfasst: Mi Nov 02, 2005 12:24 
Hello guys,

Since you are working on Quake 3 to Delphi conversion, maybe you have some ideas on the following problem:

In C++ there is a function to assign operator to a class,i thougt it was called Operator Overloading.
Let's say we got a vector class:

Code:
  1.  
  2. vector {
  3.    float   x,y,z  
  4. }
  5.  


In C++ it is possible to make a function which handles, for example, the substration of the 2 classes.
So when you use

Code:
  1.  
  2. vector1 - vector2
  3.  


it is using your own made function.

I know that with Delphi 2005 and .NET it is possible, but how do you guys solve it without .NET?

Thanks in advance

-Ice3


Nach oben
  
Mit Zitat antworten  
 Betreff des Beitrags:
BeitragVerfasst: Mi Nov 02, 2005 12:55 
Offline
DGL Member

Registriert: Mi Dez 15, 2004 20:36
Beiträge: 454
Wohnort: Wien, Österreich
In delphi32 there is no operator overloading. You simply must write your own function witch does that. And if you declare and implement the function in the same unit where you declared your classes, this function could serve as an "friend" function in C++ manner.

Example:
Code:
  1. type
  2.   TVector = class
  3.     private
  4.       fX, fY, Fz : Single;
  5.     public
  6.       property X:Single read fX write fX;
  7.       property Y:Single read fY write fY;
  8.       property Z:Single read fZ write fZ;
  9.   end;
  10.  
  11.  
  12. procedure VectorAdd( v1, v2, result :TVector );
  13.  
  14. implementation
  15.  
  16. procedure VectorAdd( v1, v2, result :TVector );
  17. begin
  18.   result.fX := v1.fX + v2.fX; // you cann access the private members since you are in the same unit !!!
  19.   result.fY := v1.fY + v2.fY; // this is like a friend function in c++
  20.   result.fZ := v1.fZ + v2.fZ;
  21. end;
  22.  


And Quake3 is written in C, so there are no classes there, and of course no operator overloading.

_________________
"Meine Mutter sagt : 'Dumm ist der, der Dummes tut'." - Forrest Gump


Nach oben
 Profil  
Mit Zitat antworten  
 Betreff des Beitrags:
BeitragVerfasst: Mi Nov 02, 2005 13:33 
Offline
DGL Member
Benutzeravatar

Registriert: Sa Dez 28, 2002 11:13
Beiträge: 2244
Delphi2006 supports operator overloading also in Win32. The syntax will be the same as for the .Net version.


Nach oben
 Profil  
Mit Zitat antworten  
 Betreff des Beitrags:
BeitragVerfasst: Fr Nov 04, 2005 10:44 
Thanks, you both!

I will use sniper_w code for now, but when Delphi 2006 comes out, i'll look into that!

Thanks again

-Ice3


Nach oben
  
Mit Zitat antworten  
 Betreff des Beitrags:
BeitragVerfasst: Do Dez 01, 2005 09:29 
Offline
DGL Member
Benutzeravatar

Registriert: Di Mai 18, 2004 16:45
Beiträge: 2621
Wohnort: Berlin
Programmiersprache: Go, C/C++
You can use FreePascal, it support stuff like this.
You find it under this link http://www.freepascal.org

irony_mode:=true;
But it is a free compiler and you don't pay money, its cross and build much faster code like delphi and gcc.
It have no ide and for OpenGL you need a visuell development envoirement because only on this way you can use the not existing vcl on your OGL Projekt.
irony_mode:=false;

_________________
"Wer die Freiheit aufgibt um Sicherheit zu gewinnen, der wird am Ende beides verlieren"
Benjamin Franklin

Projekte: https://github.com/tak2004


Nach oben
 Profil  
Mit Zitat antworten  
 Betreff des Beitrags:
BeitragVerfasst: Do Dez 08, 2005 13:15 
Offline
DGL Member

Registriert: Sa Nov 12, 2005 04:05
Beiträge: 7
Wohnort: eu
sniper hat geschrieben:
In delphi32 there is no operator overloading. You simply must write your own function witch does that. And if you declare and implement the function in the same unit where you declared your classes, this function could serve as an "friend" function in C++ manner.

Example:
Code:
  1. type
  2.   ............
  3.  


And Quake3 is written in C, so there are no classes there, and of course no operator overloading.


and C#? Sorry C are more performant language, as english compare with german's + ae, oe, ue etc.

MfG
berlinea screen TFT

_________________
move it


Nach oben
 Profil  
Mit Zitat antworten  
 Betreff des Beitrags:
BeitragVerfasst: Do Dez 08, 2005 18:14 
Offline
DGL Member

Registriert: Mi Dez 15, 2004 20:36
Beiträge: 454
Wohnort: Wien, Österreich
Zitat:
and C#? Sorry C are more performant language, as english compare with german's + ae, oe, ue etc.
:shock: If only i could understand what you mean with this ad what it has to do with anything i said.

_________________
"Meine Mutter sagt : 'Dumm ist der, der Dummes tut'." - Forrest Gump


Nach oben
 Profil  
Mit Zitat antworten  
 Betreff des Beitrags:
BeitragVerfasst: Do Dez 08, 2005 19:30 
Offline
DGL Member
Benutzeravatar

Registriert: Sa Dez 28, 2002 11:13
Beiträge: 2244
He probably means that a pure language without any extensions is the fastest, but that's obviously wrong.


Nach oben
 Profil  
Mit Zitat antworten  
 Betreff des Beitrags:
BeitragVerfasst: Do Dez 08, 2005 20:46 
Offline
DGL Member
Benutzeravatar

Registriert: Di Mai 18, 2004 16:45
Beiträge: 2621
Wohnort: Berlin
Programmiersprache: Go, C/C++
The fastest language is that which use a compiler who generate the fastest asm routine(not the shortest because every asm call need different cycles for a call).
Thats mean if you have a compiler which check every assignment for valid values and have no checker for stupid codeblocks like "if 1=1 then" or use other not needed code it will be slow down the binary. C must not the fastest and Java not the slowest because its dependent on compiler.

_________________
"Wer die Freiheit aufgibt um Sicherheit zu gewinnen, der wird am Ende beides verlieren"
Benjamin Franklin

Projekte: https://github.com/tak2004


Nach oben
 Profil  
Mit Zitat antworten  
 Betreff des Beitrags:
BeitragVerfasst: Fr Dez 09, 2005 23:01 
Offline
DGL Member
Benutzeravatar

Registriert: Sa Nov 13, 2004 11:00
Beiträge: 229
Wohnort: Steinhude
not to forget the degree of optimizations a specific compiler depends mostly on the kind of routines it's given, because even the compiler generating the fastest code in general has some points, where it doesn't optimize to the perfect implementation (probably most of the time) and other compilers which are optimized better for this job will generate a better solution for the given task


Nach oben
 Profil  
Mit Zitat antworten  
 Betreff des Beitrags:
BeitragVerfasst: So Dez 11, 2005 03:08 
Offline
Guitar Hero
Benutzeravatar

Registriert: Do Sep 25, 2003 15:56
Beiträge: 7804
Wohnort: Sachsen - ERZ / C
Programmiersprache: Java (, Pascal)
Java code is defenitly slower then normal c/pascal code because it has to be "compiled" at the first run. But that's not the point... ;)

_________________
Blog: kevin-fleischer.de und fbaingermany.com


Nach oben
 Profil  
Mit Zitat antworten  
 Betreff des Beitrags: MagicGeometry
BeitragVerfasst: Do Dez 15, 2005 00:14 
Offline
DGL Member

Registriert: Sa Nov 12, 2005 04:05
Beiträge: 7
Wohnort: eu
Code:
  1.  
  2. type
  3.       TMagicVector = class
  4.       private
  5.       FX, FY, FZ, FU : Single;
  6.       public
  7.  
  8.       property X:Single read FX write FX;
  9.       property Y:Single read FY write FY;
  10.       property Z:Single read FZ write FZ;
  11.       property Z:Single read FU write FU;
  12.  
  13.       end;
  14.  
  15.       procedure VectorAdd( v1, v2, result :TMagicVector );
  16.  
  17.       implementation
  18.  
  19.       procedure VectorAdd( v1, v2, result :TMagicVector );
  20. .
  21.       begin
  22.  
  23.       result.FX := v1.FX + v2.FX;
  24.       result.FY := v1.FY + v2.FY;
  25.       result.FZ := v1.FZ + v2.FZ;
  26.       result.FU := v1.FU + v2.FU;
  27.  
  28.       end;
  29.  

_________________
move it


Zuletzt geändert von delphiXYZ am Do Dez 15, 2005 00:24, insgesamt 1-mal geändert.

Nach oben
 Profil  
Mit Zitat antworten  
 Betreff des Beitrags:
BeitragVerfasst: Do Dez 15, 2005 00:16 
Offline
DGL Member

Registriert: Sa Nov 12, 2005 04:05
Beiträge: 7
Wohnort: eu
Flash hat geschrieben:
Java code is defenitly slower then normal c/pascal code because it has to be "compiled" at the first run. But that's not the point... ;)
and Quick Basic is "implementator", other ? 8)

_________________
move it


Nach oben
 Profil  
Mit Zitat antworten  
 Betreff des Beitrags:
BeitragVerfasst: Do Dez 15, 2005 00:22 
Offline
DGL Member

Registriert: Sa Nov 12, 2005 04:05
Beiträge: 7
Wohnort: eu
sniper hat geschrieben:
.......
Code:
  1.  
  2.   TVector = class
  3.     private
  4.       fX, fY, Fz : Single; //sorry C will upper letter error message debugged Fz or fZ?
  5.     public
  6.       property X:Single read fX write fX;
  7.       property Y:Single read fY write fY;
  8.       property Z:Single read fZ write fZ;
  9.   end;
  10.  
  11.  
  12. procedure VectorAdd( v1, v2, result :TVector );
  13.  
  14. implementation
  15.  
  16. procedure VectorAdd( v1, v2, result :TVector );
  17. begin
  18.   result.fX := v1.fX + v2.fX; // you cann access the private members since you are in the same unit !!!
  19.   result.fY := v1.fY + v2.fY; // this is like a friend function in c++
  20.   result.fZ := v1.fZ + v2.fZ;
  21. end;
  22.  


And Quake3 is written in C, so there are no classes there, and of course no operator overloading.

_________________
move it


Nach oben
 Profil  
Mit Zitat antworten  
 Betreff des Beitrags:
BeitragVerfasst: Fr Dez 23, 2005 09:06 
Offline
DGL Member
Benutzeravatar

Registriert: Mo Apr 25, 2005 17:51
Beiträge: 464
sniper hat geschrieben:
Code:
  1.  
  2.   result.fY := v1.fY + v2.fY; // this is like a friend function in c++
  3.  



That´s wrong. A friend function means, that an other class or function has access to protected and private elements of a class.

In this case it' s an instance of the same class type, so I can use all private things, because "i am in the same class type". That`s the normal way of object orientaded programming :-)


Nach oben
 Profil  
Mit Zitat antworten  
Beiträge der letzten Zeit anzeigen:  Sortiere nach  
Ein neues Thema erstellen Auf das Thema antworten  [ 18 Beiträge ]  Gehe zu Seite 1, 2  Nächste
Foren-Übersicht » English » English Programming Forum


Wer ist online?

Mitglieder in diesem Forum: 0 Mitglieder und 26 Gäste


Du darfst keine neuen Themen in diesem Forum erstellen.
Du darfst keine Antworten zu Themen in diesem Forum erstellen.
Du darfst deine Beiträge in diesem Forum nicht ändern.
Du darfst deine Beiträge in diesem Forum nicht löschen.
Du darfst keine Dateianhänge in diesem Forum erstellen.

Suche nach:
Gehe zu:  
cron
  Powered by phpBB® Forum Software © phpBB Group
Deutsche Übersetzung durch phpBB.de
[ Time : 5.275s | 17 Queries | GZIP : On ]