CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4

Threaded View

  1. #1
    Join Date
    Jan 2010
    Posts
    45

    Question 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.

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
  •  





Click Here to Expand Forum to Full Width

Featured