Posts

Showing posts from March, 2010

C++: Link errors caused by inline functions

Spanish version / Versión en Español When we want a C++ function to be inlined, that is, to have its calls replaced by its code in order to save the calling overhead, one way to achieve is to declare and define it in the .h file, and add the inline keyword. However, that's just a hint to the compiler, he'll decide whether to inline it or not. However, if we are keen on separating declaration and definition, we should declare the function in the .h file, without the inline keyword, and define it in the .cpp with the inline keyword. So far, so good. But there's a catch: If we go for the "cpp inline" approach, and the function is called from another compilation unit (.cpp), we'll get a linking error saying something like the function definition cannot be found. In this case, we have two choices: Place the function definition in the .h file, but outside of the class declaration. This avoids cluttering its interface. This way

C++: Errores de linking generados por el uso de inline

Versión en inglés / English version Cuando queremos que una función C++ sea inline, o sea, que sus llamadas sean reemplazadas en tiempo de compilación por su código a fin de evitar el overhead de la llamada, podemos definir la función dentro de la declaración de la clase y anteponer la palabra reservada inline. De todas formas, eso es sólo un "consejo" para el compilador, quien decidirá si le conviene o no. Si nos molesta tener que definir en el .h, podemos sólo declarar la función ahí sin la palabra reservada inline, y definirla en el .cpp con la palabra reservada inline. Hasta acá, todo bien. Pero puede haber problemas: si usamos inline en el cpp, y queremos usar esa función desde otra unidad de compilación (otro .cpp), nos saltará un error de link diciendo algo como que no logra encontrar la definición de la función. En este caso, si insistimos con usar inline, tenemos dos opciones: Poner la definición en el .h, pero afuera de la dec

VB.NET: Overloading, shadowing and overriding

Spanish version / Versión en Español Overloading : When two methods have the same name, return type and different arguments (in type or quantity), we say they are overloaded. If their arguments are the same, they must be in different classes to avoid a duplicate definition. If those classes are unrelated, it's alright and we're still in the overload case. But if one class inherits from another, either Shadowing or Overriding can ocurr. Shadowing : This is what happens by default in VB.NET. Basically, the definition used when invoking is determined by the reference's type, not by the object's intrinsic type (the one with which it was created). In other word, there is no strict polymorphism/virtual mechanism. For example: Imports System Public Class Base Public Sub ShadowedSub() Console.WriteLine("ShadowedSub:Base") End Sub End Class Public Class Derived : Inherits Base Public Sub ShadowedSub() Console.WriteLine("

VB.NET: Overloading, shadowing y overriding

Versión en inglés / English version Overloading : En general, hay overloading cuando dos o más métodos tienen el mismo nombre y devuelven lo mismo, pero los argumentos que reciben son diferentes en tipo y/o cantidad. Cuando nombre, tipo devuelto y argumentos coinciden, ello sólo puede ocurrir en clases diferentes para que no haya una definición duplicada. Si son clases sin relación, no hay problema. Pero si una hereda de otra, puede ocurrir Shadowing u Overriding. Shadowing : Esto es lo que ocurre por defecto en VB.NET. Básicamente, dado un objeto, no se llama la definición dada por su tipo intrínseco, sino por el aparente. En otras palabras, no hay polimorfismo. Ejemplo: Imports System Public Class Base Public Sub ShadowedSub() Console.WriteLine("ShadowedSub:Base") End Sub End Class Public Class Derived : Inherits Base Public Sub ShadowedSub() Console.WriteLine("ShadowedSub:Derived") End Sub End Class Public Class T

Massive file rename in Windows XP

Spanish version / Versión en Español The Windows XP console (Start->Run...->cmd) is not so bad: With the rename command, it is possible to rename multiple files using wildcards. For example: rename * *.txt #Adds the .txt extension to all files rename *.dat *.rar #Changes all the .dat's extension to .rar

Renombrando archivos masivamente en XP

Versión en inglés / English version La consola de Windows (Inicio->Ejecutar->cmd) no es tan pedorra: Con el comando rename podemos renombrar archivos masivamente usando patrones sencillos. Ejemplos: rename * *.txt #Agrega extensión .txt a todos rename *.dat *.rar #Cambia extensión a todos los .dat