C++: Vector Problem

Started by
7 comments, last by choffstein 19 years, 7 months ago
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.
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
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. :)

Jeff Thompson
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.
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.
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.
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.
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.
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]

This topic is closed to new replies.

Advertisement