Questo sito utilizza cookies solo per scopi di autenticazione sul sito e nient'altro. Nessuna informazione personale viene tracciata. Leggi l'informativa sui cookies.
Username: Password: oppure
C# / VB.NET - Problema operatore
Forum - C# / VB.NET - Problema operatore

Avatar
Thejuster (Admin)
Guru^2


Messaggi: 2305
Iscritto: 04/05/2008

Segnala al moderatore
Postato alle 10:31
Venerdì, 22/01/2016
Durante la creazione di alcune mie librerie mi sono imbattuto in un errore
che non riesco a venirne a capo.

Vi allego la parte interessata

Codice sorgente - presumibilmente C++

  1. //*******************************
  2.         // WebGL Module by Thejuster
  3.         // A js Module Exporter
  4.         //------------------------------
  5.  
  6.  
  7.         /// <summary>
  8.         /// Vector2 Dimension
  9.         /// </summary>
  10.         [ImmutableObject(true), Serializable]
  11.         public struct Vector2
  12.         {
  13.  
  14.             private float _x;
  15.             private float _y;
  16.  
  17.             /// <summary>
  18.             /// Set Vector2 Location Float Point
  19.             /// </summary>
  20.             /// <param name="X">X</param>
  21.             /// <param name="Y">Y</param>
  22.             public Vector2(float X,float Y)
  23.             {
  24.                 _x = X;
  25.                 _y = Y;
  26.             }
  27.  
  28.             /// <summary>
  29.             /// Get X location
  30.             /// </summary>
  31.             public float X
  32.             {
  33.                 get { return _x; }
  34.  
  35.             }
  36.  
  37.             /// <summary>
  38.             /// Get Y Locatino
  39.             /// </summary>
  40.             public float Y
  41.             {
  42.                 get { return _y; }
  43.             }
  44.  
  45.             /// <summary>
  46.             /// Return value to string format
  47.             /// </summary>
  48.             /// <returns>return value</returns>
  49.             public override string ToString()
  50.             {
  51.                 return string.Format("{0}:{1}", X, Y);
  52.             }
  53.  
  54.          
  55.         }
  56.  
  57.    
  58.         public static Vector2 operator +(Vector2 p1, Vector2 p2)
  59.         {
  60.             return new Vector2(
  61.                 p1.X + p2.X,
  62.                 p1.Y + p2.Y);            
  63.         }
  64.  
  65.          //Translate
  66.          public static Vector2 operator *(Vector2 vec, float num)
  67.         {
  68.             Vector2 v = new Vector2();
  69.             v.X = num * vec.X;
  70.             v.Y = num * vec.Y;
  71.            
  72.             return v;
  73.         }



L'errore e sul void operator +

EDIT: Ecco il messaggio di errore

"Errore    1    Uno dei parametri di un operatore binario deve essere il tipo che lo contiene

Non capisco bene questo errore.
Qualcuno si è già imbattuto in questa situazione?

Il tipo che lo contiene e chiaramente il Vector2
quindi non capisco perché ho questo problema
Entrambi i metodi restituiscono un errore.


Ultima modifica effettuata da Thejuster il 22/01/2016 alle 11:24


https://mire.forumfree.it/ - Mire Engine
C# UI Designer
PM Quote
Avatar
Thejuster (Admin)
Guru^2


Messaggi: 2305
Iscritto: 04/05/2008

Segnala al moderatore
Postato alle 16:06
Venerdì, 22/01/2016
Risolto..
Basta sostituire la struttura con la classe.



https://mire.forumfree.it/ - Mire Engine
C# UI Designer
PM Quote