?
Solved

Structure

Posted on 2002-05-29
3
Medium Priority
?
186 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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 200 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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

Unlike C#, C++ doesn't have native support for sealing classes (so they cannot be sub-classed). At the cost of a virtual base class pointer it is possible to implement a pseudo sealing mechanism The trick is to virtually inherit from a base class…
C++ Properties One feature missing from standard C++ that you will find in many other Object Oriented Programming languages is something called a Property (http://www.experts-exchange.com/Programming/Languages/CPP/A_3912-Object-Properties-in-C.ht…
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…
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.

762 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