Trouble Passing a structure around?

Hi,
My question is this, I have multiple files that need to use one structure it looks like:
typedef struct StorageInfo {
char Mask[MAX_PATH];
char Directory[MAX_PATH];
char Condition[MAX_PATH];

int month;
int year;
int day;

char newDirectory[MAX_PATH];
}StorageInfo;

I declared it in Search.h, now Files.cpp and Parse.cpp need to use it as well as Search.cpp. I included Search.h in all the the .cpp files above. But Yet I m getting errors in Parse.cpp like 'StorageInfo' undeclared. Even though I included Search.h both in Parse.h and Parse.cpp

I created the structure in Files.cpp as follows,
StorageInfo * s = NULL;
s = (StorageInfo * ) malloc(sizeof(StorageInfo));
I need to be able to pass it from class functions to global functions and back. I had it as *& so it gets modified and stays modified. But I can't get it compile.
Then I get weird erros in Parse.cpp like
'<Unknown>' function-style intializers appears to be function definition
I have never seen these errors before.
Any ideas on how to get my program to love my structure? lol
Thanks.
P.S. This in VC++ 6.0 MFC Project... But i posted the question here because it isn't mfc releated I dont' think.
Thanks again.
cod3po3tAsked:
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

x
 
bcladdConnect With a Mentor Commented:
(1) I get no error with Borland C++ 5.5 (after commenting out "stdafx.h"). Studio .NET gives your errors until I rearrange the header files:
 
#include <windows.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "stdafx.h"
#include "info.h"
#include "parse.h"

I don't see why this fixes the problem but it does.

Hope this helps, -bcl
0
 
bcladdCommented:
Are you really using C++ or are you using C? If you are using C++ it is probably clearer to forgo the typedef:

struct StorageInfo {
char Mask[MAX_PATH];
char Directory[MAX_PATH];
char Condition[MAX_PATH];

int month;
int year;
int day;

char newDirectory[MAX_PATH];
};

Now, in C++, you can use the new operator to allocate a new StorageInfo on the heap. Then use a typedef for the pointer:

typedef StorageInfo * StoragePtr;

Now it should be easy to declare a variable and use it:

StoragePtr s = NULL;
s = new StorageInfo;

No constructor is provided so C++ compiler will generate one for you.

Use delete to get release the information:

delete s;

If you must use malloc, you should still use the first declaration above as it should get rid of the reported compiler error. (note: above code is untested but should be correct).

-bcl
0
 
cod3po3tAuthor Commented:
After doing what you said I m only getting errors in the parse files. Below are the files.

parse.h
#ifndef _parse_h
#define _parse_h

#include "info.h"

bool parseDate(StoragePtr s);
bool parseMask(StoragePtr s);
bool parseDirectory(StoragePtr s);
#endif

Parse.cpp
bool parseDate(StoragePtr s)
{
return true;
}

bool parseDirectory(StoragePtr s)
{
return true;
}
bool parseMask(StoragePtr s)
{
     return true;
}

info.h
#ifndef _info_h
#define _info_h
struct StorageInfo {
char Mask[MAX_PATH];
char Directory[MAX_PATH];
char Condition[MAX_PATH];

int month;
int year;
int day;

char newDirectory[MAX_PATH];
};
typedef StorageInfo * StoragePtr;
#endif _info_h

I m getting errors like, StoragePtr undefined, syntax error missing ) before identifier s, syntax error: )
All teh errors are in parse.cpp and point to either the prototype or the { each function has the same errors.
Any ideas?
0
The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

 
bcladdCommented:
You never include parse.h in parse.cpp.

That should fix the problem.
0
 
cod3po3tAuthor Commented:
No I didn't paste the includes these are my following includes:
#include "info.h"
#include "parse.h"
#include <windows.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "stdafx.h"

Any new ideas?
0
 
cod3po3tAuthor Commented:
You rule man! Thanks a ton!
0
All Courses

From novice to tech pro — start learning today.