class has no constructors

V

Vincent R

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...
 
V

Victor Bazarov

Vincent said:
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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,230
Members
46,819
Latest member
masterdaster

Latest Threads

Top