开发者

Define the prototype of a function with a std::vector as input parameter in an header

开发者 https://www.devze.com 2023-04-09 04:49 出处:网络
I\'m getting crazy since i\'m not able to define the prototype of a function i\'m actually using. What i\'m doing is create an header file called func1.hwhere i define this prototype (that\'s because

I'm getting crazy since i'm not able to define the prototype of a function i'm actually using. What i'm doing is create an header file called func1.hwhere i define this prototype (that's because i need to invoke this function from some other function implemented elsewhere):

void FileVector(std::vector<Files> &,const char*,bool);

Where Filesis a struct defined in func1.cpp

struct Files{
        HANDL开发者_StackOverflowE h;
        WIN32_FIND_DATA info;
        } file;

I have also another function that accept a std::vector<Files> & as input parameter but when i try to compile (using Eclipse C++) i'm getting those errors:

/FileVector.h:11:22: error: variable or field 'FileVector' declared void
..\/FileVector.h:11:17: error: 'vector' is not a member of 'std'
..\/FileVector.h:11:29: error: 'Files' was not declared in this scope

I've tryied to include several directive in the header file..for example declaring the struct in the header and including vector header do the trick but this way i got loads of "multiple definitions/first defined here" error. What can i do?

EDIT

Now my header looks like:

#ifndef FILEVECTOR_H_
#define FILEVECTOR_H_
#include <vector>
#include <windows.h>

 struct Files{
        HANDLE h;
        WIN32_FIND_DATA info;
        };

 void FileVector(std::vector<Files> &,const char*,bool);

 #endif /* FILEVECTOR_H_ */

At this point, i need to declare another prototype in another header:

void ProcessInput(vector<Files>&);

but i can't use the same trick as above cause i'll have to re-define the Files struct. How can i solve this?


Make sure to include <vector> in your header file. You also mention that the definition of Files is within the cpp file, you should move it to the header as well.

Also place proper header guards to avoid multiple definition errors:

#ifndef MY_HEADER_FILE_GUARD
#define MY_HEADER_FILE_GUARD

... your content here ...

#endif /*MY_HEADER_FILE_GUARD*/

Update: Simply including filevector.h from your new header would do. However, it looks like Files should be defined in a header of its own and included from the two headers that make use of it.

0

精彩评论

暂无评论...
验证码 换一张
取 消