c ++ builder. Variables static in class [closed]


I have little builder and I try to do an exercise in which values of the position and size of the form are stored in static variables, based on Borland C ++ builder 6 developer's guide pages 86 and 87. For this I pretended create a class in a .h file

class VGlobales {

    // atributos
    private: static int posicionAlto;
    private: static int posicionAncho;
    private: static int posicionArriba;
    private: static int posicionIzquierda;

    // constructor privado
    private: VGlobales();

    // métodos setting
    public: static void setposicionAlto(
        int nuevaposicionAlto) {posicionAlto = nuevaposicionAlto;}
    public: static void setposicionAncho(
        int nuevaposicionAncho) {posicionAncho = nuevaposicionAncho;}
    public: static void setposicionArriba(
        int nuevaposicionArriba) {posicionArriba = nuevaposicionArriba;}
    public: static void setposicionIzquierda(
        int nuevaposicionIzquierda) {posicionIzquierda =     nuevaposicionIzquierda;}

    // métodos getting
    public: static int getposicionAlto() {return posicionAlto;}
    public: static int getposicionAncho() {return posicionAncho;}
    public: static int getposicionArriba() {return posicionArriba;}
    public: static int getposicionIzquierda() {return posicionIzquierda;}

and later in each form before closing store these values


Sorry if it's a little messed up but I've modified it many times, I can not find the right way to include the newposition variables by calling the methods.

asked by hexadecimal 31.03.2017 в 13:51

1 answer


The definition of static variables consists of 2 parts:

  • Statement.
  • Instanciación.
  • In your code, you do the 1st part. You declare the variable.

    You would miss the second one: Instanciarla .

    To do this, create a separate file, archivo.cpp , that contains the following:

    int VGlobales::posicionAlto;
    int VGlobales::posicionAncho;
    int VGlobales::posicionArriba;
    int VGlobales::posicionIzquierda;

    That should be enough with that.

    answered by 31.03.2017 / 14:56