Solved

Structure

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

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
is twain_32.dll cmpatible with windows 10 ? 10 184
How to convert MFC::CString to UTF8 wchar_t* 10 277
Error creating a new C++ project in ,net 20 41
Need some help with mailto 16 20
When writing generic code, using template meta-programming techniques, it is sometimes useful to know if a type is convertible to another type. A good example of when this might be is if you are writing diagnostic instrumentation for code to generat…
Container Orchestration platforms empower organizations to scale their apps at an exceptional rate. This is the reason numerous innovation-driven companies are moving apps to an appropriated datacenter wide platform that empowers them to scale at a …
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 be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

809 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