Solved

Structure

Posted on 2002-05-29
3
178 Views
Last Modified: 2010-04-02
I have structure:
 struct CUSTOMVERTEX { FLOAT x, y, z, rhw; DWORD color; };
 const int myarraysize=3;
 CUSTOMVERTEX new_Vertices[myarraysize];

I trying this:
 new_Vertices[0].x = 60.0f;
 new_Vertices[0].y = 60.0f;
 new_Vertices[0].z = 0.5f;
 new_Vertices[0].rhw = 1.0f;
 new_Vertices[0].color = 0xffff0000;
Works fine, but I don't want it like this...

I trying this:
 new_Vertices[0] =  {60.0f,  60.0f, 0.5f, 1.0f, 0xffff0000};
But it generates syntax errors. Why?

Sorry for my English.
Tnx.



0
Comment
Question by:rv_man
3 Comments
 
LVL 32

Expert Comment

by:jhance
ID: 7042152
This syntax is similar to an INITIALIZER and is only legal in a DECLARATION, not as an ASSIGNMENT.

You could try:

CUSTOMVERTEX new_Vertices[myarraysize] = {60.0f,  60.0f, 0.5f, 1.0f, 0xffff0000};
0
 
LVL 86

Accepted Solution

by:
jkr earned 50 total points
ID: 7042157
Try

CUSTOMVERTEX v =  {60.0f,  60.0f, 0.5f, 1.0f, 0xffff0000};

new_Vertices[0] = v;
0
 
LVL 30

Expert Comment

by:Axter
ID: 7042170
If you want to initialize the entire array, you can try the following:

const int myarraysize=3;
CUSTOMVERTEX new_Vertices[myarraysize] = {
{60.0f,  63.0f, 0.5f, 1.0f, 0xffff0000},
{61.0f,  64.0f, 0.5f, 1.0f, 0xffff0000},
{62.0f,  65.0f, 0.5f, 1.0f, 0xffff0000}
};
0

Featured Post

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

Often, when implementing a feature, you won't know how certain events should be handled at the point where they occur and you'd rather defer to the user of your function or class. For example, a XML parser will extract a tag from the source code, wh…
Written by John Humphreys C++ Threading and the POSIX Library This article will cover the basic information that you need to know in order to make use of the POSIX threading library available for C and C++ on UNIX and most Linux systems.   [s…
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…

705 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now