Newbie: different problem with references

Discussion in 'C++' started by Manuel, Jan 14, 2006.

  1. Manuel

    Manuel Guest

    Hi...yet, another problem with references...sorry...

    This is my singleton header:

    -----------------------------------------
    class MHwindow {
    private:
    static MHwindow MHw;

    GLuint texture;

    //Constructor is private, because this is a singleton
    MHwindow(GLuint &);
    MHwindow& operator=(MHwindow&); // Disallowed
    MHwindow(const MHwindow&); // Disallowed

    public:
    static MHwindow& instance() { return MHw; }

    void setTexture(GLuint);
    GLuint getTextures();
    };
    ----------------------------------------

    This is my singleton cpp file:

    ----------------------------------------
    MHwindow::MHwindow(GLuint & textur)
    {
    pngInfo texInfo;
    textur = pngBind("pippo.png", PNG_NOMIPMAP, PNG_ALPHA, NULL, GL_CLAMP,
    GL_NEAREST, GL_LINEAR);
    }

    void MHwindow::setTexture(GLuint i){texture = i;};
    GLuint MHwindow::getTextures(){return texture;};

    ----------------------------------------

    this is the usage I'm trying:
    ----------------------------------------
    GLuint textureID;
    MHwindow MHwindow::MHw(textureID);
    MHwindow& MainWindow = MHwindow::instance();
    ----------------------------------------

    and....this is the retrun error:

    In function `Z41__static_initialization_and_destruction_0ii':
    undefined reference to `MHwindow::MHwindow(unsigned int)'


    I'm trying to pass a reference to constructor.

    :-(
    Manuel, Jan 14, 2006
    #1
    1. Advertising

  2. Manuel wrote:
    >
    > I'm trying to pass a reference to constructor.
    >



    But MHwindow ctors are private :)

    Cheers
    --
    Mateusz Åoskot
    http://mateusz.loskot.net
    =?UTF-8?B?TWF0ZXVzeiDFgW9za290?=, Jan 14, 2006
    #2
    1. Advertising

  3. Manuel

    Manuel Guest

    Mateusz Åoskot wrote:

    >
    > But MHwindow ctors are private :)



    Because is singleton, they must be private.
    If I delete all "&", it work, so the problem is my use of reference...
    Manuel, Jan 14, 2006
    #3
  4. Manuel

    Daniel T. Guest

    In article <43c84415$0$1077$>,
    Manuel <> wrote:

    > Hi...yet, another problem with references...sorry...
    >
    > This is my singleton header:
    >
    > -----------------------------------------
    > class MHwindow {
    > private:
    > static MHwindow MHw;
    >
    > GLuint texture;
    >
    > //Constructor is private, because this is a singleton
    > MHwindow(GLuint &);
    > MHwindow& operator=(MHwindow&); // Disallowed
    > MHwindow(const MHwindow&); // Disallowed
    >
    > public:
    > static MHwindow& instance() { return MHw; }
    >
    > void setTexture(GLuint);
    > GLuint getTextures();
    > };
    > ----------------------------------------
    >
    > This is my singleton cpp file:
    >
    > ----------------------------------------
    > MHwindow::MHwindow(GLuint & textur)
    > {
    > pngInfo texInfo;
    > textur = pngBind("pippo.png", PNG_NOMIPMAP, PNG_ALPHA, NULL, GL_CLAMP,
    > GL_NEAREST, GL_LINEAR);
    > }
    >
    > void MHwindow::setTexture(GLuint i){texture = i;};
    > GLuint MHwindow::getTextures(){return texture;};
    >
    > ----------------------------------------
    >
    > this is the usage I'm trying:
    > ----------------------------------------
    > GLuint textureID;
    > MHwindow MHwindow::MHw(textureID);
    > MHwindow& MainWindow = MHwindow::instance();
    > ----------------------------------------


    What file is the above code in?


    --
    Magic depends on tradition and belief. It does not welcome observation,
    nor does it profit by experiment. On the other hand, science is based
    on experience; it is open to correction by observation and experiment.
    Daniel T., Jan 15, 2006
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Roger Leigh
    Replies:
    8
    Views:
    434
    Karl Heinz Buchegger
    Nov 17, 2003
  2. Replies:
    3
    Views:
    447
    Victor Bazarov
    Nov 10, 2004
  3. DanielEKFA
    Replies:
    8
    Views:
    601
    DanielEKFA
    May 16, 2005
  4. Replies:
    8
    Views:
    710
    Bruno Desthuilliers
    Dec 12, 2006
  5. Lars Willich
    Replies:
    13
    Views:
    833
    Ian Shef
    Oct 23, 2007
Loading...

Share This Page