class has no constructors

Discussion in 'C++' started by Vincent R, Apr 7, 2009.

  1. Vincent R

    Vincent R Guest

    Hi,

    When trying to compile the following code I get an error with MS
    compiler error C2514: 'GlyphTexCoords' : class has no constructors



    /* Forward declarations */
    struct Vector2f;
    struct GlyphPosition;
    struct GlyphTexCoords;
    struct GlyphColors;

    /////////////////////////////////////////////////////////////////////
    // class OpenGLFont
    //
    class OpenGLFont
    {
    public:
    vector<GlyphTexCoords> TextureCoordinates;

    void SetFont(CFont font)
    {

    ...

    float uStart = x / fSquareDim;
    float uEnd = (x + CharacterWidths) / fSquareDim;
    float vEnd = (y + myHeight) / fSquareDim;

    TextureCoordinates = GlyphTexCoords(uStart, vStart, uEnd, vEnd);

    }
    }; //OpenGLFont

    struct GlyphTexCoords
    {
    Vector2f BottomLeft;
    Vector2f TopLeft;
    Vector2f BottomRight;
    Vector2f TopRight;

    GlyphTexCoords()
    {}

    GlyphTexCoords(float left, float top, float right, float bottom)
    {
    TopLeft.X = BottomLeft.X = left;
    TopLeft.Y = TopRight.Y = top;
    TopRight.X = BottomRight.X = right;
    BottomLeft.Y = BottomRight.Y = bottom;
    }
    };

    Don't understand becaue there is a constructor...
     
    Vincent R, Apr 7, 2009
    #1
    1. Advertising

  2. Vincent R wrote:
    > When trying to compile the following code I get an error with MS
    > compiler error C2514: 'GlyphTexCoords' : class has no constructors
    >
    >
    >
    > /* Forward declarations */
    > struct Vector2f;
    > struct GlyphPosition;
    > struct GlyphTexCoords;


    Here you declare that 'GlyphTexCoords' is some kind of a class.

    > struct GlyphColors;
    >
    > /////////////////////////////////////////////////////////////////////
    > // class OpenGLFont
    > //
    > class OpenGLFont
    > {
    > public:
    > vector<GlyphTexCoords> TextureCoordinates;


    I am not sure this is actually legal. A template argument cannot be an
    incomplete type, IIRC. If VC++ allows you to get away with that, that's
    fine, but expect portability issues.

    >
    > void SetFont(CFont font)
    > {
    >
    > ...
    >
    > float uStart = x / fSquareDim;
    > float uEnd = (x + CharacterWidths) / fSquareDim;
    > float vEnd = (y + myHeight) / fSquareDim;
    >
    > TextureCoordinates = GlyphTexCoords(uStart, vStart, uEnd, vEnd);


    Compiling this function requires to know what 'GlyphTexCoords'
    constructor to call on that line. Since the class 'GlyphTexCoords' has
    not yet been defined here (it is defined below), the compiler is unable
    to compile that assignment statement.

    Take the entire function 'SetFont' and define it in a translation unit,
    as all normal code should be. Or move the definition of the
    'GlyphTexCoords' class above the definition of 'OpenGLFont'.

    >
    > }
    > }; //OpenGLFont
    >
    > struct GlyphTexCoords
    > {
    > Vector2f BottomLeft;
    > Vector2f TopLeft;
    > Vector2f BottomRight;
    > Vector2f TopRight;
    >
    > GlyphTexCoords()
    > {}
    >
    > GlyphTexCoords(float left, float top, float right, float bottom)
    > {
    > TopLeft.X = BottomLeft.X = left;
    > TopLeft.Y = TopRight.Y = top;
    > TopRight.X = BottomRight.X = right;
    > BottomLeft.Y = BottomRight.Y = bottom;
    > }
    > };
    >
    > Don't understand becaue there is a constructor...


    No, there isn't YET.

    V
    --
    Please remove capital 'A's when replying by e-mail
    I do not respond to top-posted replies, please don't ask
     
    Victor Bazarov, Apr 7, 2009
    #2
    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. Dave Rudolf
    Replies:
    12
    Views:
    8,331
    Martijn Lievaart
    Feb 6, 2004
  2. Jeremy Smith
    Replies:
    2
    Views:
    603
    Jeremy Smith
    Aug 3, 2006
  3. Jess
    Replies:
    5
    Views:
    615
    Ron Natalie
    Jun 7, 2007
  4. Peng Yu
    Replies:
    5
    Views:
    403
    Juha Nieminen
    Sep 19, 2008
  5. srp113
    Replies:
    3
    Views:
    482
Loading...

Share This Page