-
February 10th, 2011, 06:55 PM
#1
How to use Globals
Hi,
I'm trying to make a type definition and a vector (based on that type definition) global to all my forms in vc++ and it isn't working.
I have one file named "Brians_Globals.h" which is as follows:
Code:
#ifndef NAMESPACE_BRIAN
#define NAMESPACE_BRIAN
extern int id;
extern int credit;
extern struct CustomerRecords
{
std::string Building;
std::string Notes;
std::string PrimaryContact;
std::string PrimaryNumber;
std::string SecondaryContact;
std::string SecondaryNumber;
std::string Address1;
std::string Address2;
std::string City;
std::string State;
std::string ZipCode;
std::string ClientSince;
std::string Rate;
std::string PerCycle;
std::string PaymentDue;
};
extern typedef pair<std::string, struct CustomerRecords> my_pair;
extern vector<my_pair> data;
extern std::string bri;
#endif
and a file named "Brians_Globals.cpp" as follows:
Code:
#include "stdafx.h"
#include <string>
using namespace std;
string bri;
struct CustomerRecords;
typedef my_pair;
vector<my_pair> data;
int id;
int credit;
Then I use:
Code:
#include "Brians_Globals.h"
in any of the forms in the vc++ project application that need access to the globals as necessary.
When I comment out both the
Code:
typedef my_pair;
vector<my_pair> data;
from the "Brians_Globals.cpp" file and the
Code:
extern typedef pair<std::string, struct CustomerRecords> my_pair;
extern vector<my_pair> data;
from the "Brians_Globals.h" file, then everything compiles and the globals can be used in my form files as desired, but if the above aren't commented out, then many, many errors occur. Thus I know that the
Code:
typedef my_pair;
vector<my_pair> data;
from the "Brians_Globals.cpp" are declared wrong. How should I declare them in the file?
Last edited by vc_user; February 10th, 2011 at 07:01 PM.
-
February 11th, 2011, 08:02 AM
#2
Re: How to use Globals
typedefs are defines, and don't need to be extern.
the typedef in the .h file (without the extern) should be enough.
the typedef in the .cpp file is wrong.
-
February 11th, 2011, 09:28 AM
#3
Re: How to use Globals
Hi thanks for your help,
I removed the "extern" from the .h file and removed the typedef statement altogether from the .cpp file and now I'm getting the following error:
Code:
C2143: syntax error : missing ';' before '<'
although there is no missing semi-colon.
-
February 11th, 2011, 09:54 AM
#4
Re: How to use Globals
Thanks for your help. I just figured it out. There was a missing "std::" statement.
Thanks again!
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|