Jump to content
  • Advertisement
Sign in to follow this  
Xiachunyi

C++: Vector Problem

This topic is 5125 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

Hello, what does this error message mean? I thought vector was a container and the type would be of the 'tMaterialInfo' struct. "74 'vector' is used as a type, but is not defined as a type."
#include <vector>
using namespace std;
...
struct tMaterialInfo
{
	char  strName[255];
	char  strFile[255];
	BYTE  color[3];
	int   texureId;
	float uTile;
	float vTile;
	float uOffset;
	float vOffset;
} ;
...
vector<tMaterialInfo> pMaterials; //This is line 74

I am using Dev C++ ver 4.9.9.0b, thank you.

Share this post


Link to post
Share on other sites
Advertisement
The snippet you posted looks alright.

I think, there must be some scope error in the "..." parts of your source.. Is this the only error you're getting?

Oxyd

Share this post


Link to post
Share on other sites
I tried this out too for you on both gcc and VisualStudio and everything worked fine. There must be something else going on in the ... parts of your code. :)

Share this post


Link to post
Share on other sites
Thanks for the quick replies.

I decided to try to explicity declare the pathname with the vector, #include <c++\vector> or #include <c++/vector>, tried both - I've seen it one way and the other so I'm not sure.

The error messages that came up next were:
bits/functexcept.h: No such file or directory.
bits/stl_algobase.h: No such file or directory.
and so on...

I think those are all header files that are declared within the vector file.

If I compiled it again with those messages, it compiles through and my executable augments in size to indicate that the code I entered has been added but if I choose to rebuild all, then all those error messages manifest again.

I probably should just take it off my code this time, since the program is for a school project, and spend more time learning more about templates.

Share this post


Link to post
Share on other sites
I believe it is because tMaterialInfo isn't anything. struct tMaterialInfo is, on the other hand. Try either of these:

1) change the name of struct tMaterialInfo to "typedef struct _tMaterialInfo{ ... } tMaterialInfo;

2) change the vector to:
vector<struct tMaterialInfo> pMaterials;


Either of those should work.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
Quote:
Original post by visage
I believe it is because tMaterialInfo isn't anything. struct tMaterialInfo is, on the other hand. Try either of these:

1) change the name of struct tMaterialInfo to "typedef struct _tMaterialInfo{ ... } tMaterialInfo;

2) change the vector to:
vector pMaterials;


Either of those should work.
This is NOT C. In C++ you don't have to do like that. The way he does is just fine.

Share this post


Link to post
Share on other sites
The AP above was me. I meant to say that the original posters code is C++ and you don't have to typedef structs like you do in C.

Share this post


Link to post
Share on other sites
I guess this one was one of those development mysteries because I could use the variables without any further problems from the compiler.

My program performs what it is suppose to regardless of that error. The first compile does not create the program because of the error but the second compile after that, try compiling again, compiles through.

I'll try digging through the code after I'm satisfied with all the other aspects since it will only be used in a school project; yes I will run it on my teacher's computer too to make sure it works.

Thank you everyone.

Share this post


Link to post
Share on other sites
whoops! See, this is why I should be doing homework and not trolling the pages of gamedev...
But as a side note: I tried it in with MingGW and it compiled fine.


Sorry for my little mess up before!
[embarrass]

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

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

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!