Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

Densun

array of structures

This topic is 6921 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I''m having trouble creating an array of structures. Here''s what I''m doing: typedef struct test_s { char* name; long id; } test_t; test_t tests[] = { { "name", 16 } }; Here''s the errors I get from the compiler: ''initializing'' : cannot convert from ''char [10]'' to ''struct frameinfo_s''. No constructor could take the source type, or constructor overload resolution was ambiguous too many initializers. What easily overlooked mistake am I making?

Share this post


Link to post
Share on other sites
Advertisement
here''s how I would do it:
typedef struct test_s
{
char* name;
long id;
} test_t, *test_t_ptr;

test_t ARRAY[10];
ARRAY.name="name";
ARRAY.id=16;

Share this post


Link to post
Share on other sites
While I could go:

test_t tests[x]; // Where x is any number.

tests[0].name = "name";
tests[0].id = 1;
.... // Repeat until whole array is filled.

It''s easier to assign the values in the declartion. That way I don''t have to continually write the name of the structure and the variables.

I still need help as to why it doesn''t work. I know it can, becuase I''ve seen code that does the same thing which works.

Share this post


Link to post
Share on other sites
Your error message says "struct frameinfo_s" but the struct you''re showing is test_s. Besides, your code compiles in my compiler, but it is a c++ compiler, that could have something to do with it, I don''t code c.

Share this post


Link to post
Share on other sites
Ooops! I forgot to mention that the structure name and fields aren''t the same as my real code, I was just giving an overview of what I was doing. Also, my compiler supports C/C++.

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!