Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > class has no constructors

Reply
Thread Tools

class has no constructors

 
 
Vincent R
Guest
Posts: n/a
 
      04-07-2009
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[i]) / fSquareDim;
float vEnd = (y + myHeight) / fSquareDim;

TextureCoordinates[i] = 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...
 
Reply With Quote
 
 
 
 
Victor Bazarov
Guest
Posts: n/a
 
      04-07-2009
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[i]) / fSquareDim;
> float vEnd = (y + myHeight) / fSquareDim;
>
> TextureCoordinates[i] = 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
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
reg constructors/copy constructors inheritance srp113 C++ 3 02-17-2009 04:01 PM
Is the possible to have all the public constructors of the publicbase class as the constructors of a derived class? Peng Yu C++ 5 09-19-2008 10:19 AM
compiler synthesized constructors/copy constructors/assignment operators Jess C++ 5 06-07-2007 11:09 AM
Copy constructors, de/constructors and reference counts Jeremy Smith C++ 2 08-02-2006 11:25 PM
Constructors that call other Constructors Dave Rudolf C++ 12 02-06-2004 03:26 PM



Advertisments