Solved

Structure

Posted on 2002-05-29
3
181 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

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

What is C++ STL?: STL stands for Standard Template Library and is a part of standard C++ libraries. It contains many useful data structures (containers) and algorithms, which can spare you a lot of the time. Today we will look at the STL Vector. …
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.

785 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