global classes

This is a discussion on global classes within the C++ Programming forums, part of the General Programming Boards category; Hello, I need to make a class that I can access by different functions to put in and retreive data ...

  1. #1
    Registered User
    Join Date
    May 2005
    Location
    Toronto, Canada
    Posts
    257

    global classes

    Hello,

    I need to make a class that I can access by different functions to put in and retreive data from. I've created a global class. I basically want to have two arrays that most of the functions in the programm can access. One would put data in there the other printf it, or something like it. Can I do tha twithout passing the arrays to every function?

    Here's the code:
    Head file class deffinition:
    Code:
    # include <stdio.h>
    # include <string.h>
    # include <stdlib.h>
    # include <malloc.h>
    # include "stdafx.h"
    #include <vector>
    
    class gBAFParmList        //Fixed/Selectable Analog Data  
    	{
    	public:
    
    		std::vector < CString > vectBP;	
    		std::vector <CString> vectParmSelected;
    	};
    one of the functions that uses the class:
    Code:
    void CInitialGUIDlg::OnButton3() 
    {
    	// Make Victor
    
    	int i=0,j;
    	FILE *out;
        out = fopen("308A.txt", "w"); // Open a file for writing
    
    	gBAFParmList PList;
    
    	fprintf(out, "\n\n>%s<\n\n", PList.vectBP[i]);
    	
    }

  2. #2
    Registered User
    Join Date
    May 2005
    Location
    Toronto, Canada
    Posts
    257
    I think I got it. Just globally creating an instance of that class seemed to work. I wasn't sure if I could do that. If there is anything wrong with this or a better way to do, let me know please.

    Thanks,

    AS.

  3. #3
    Registered User
    Join Date
    Nov 2001
    Posts
    1,348
    Depending on the design, another possible soluton is static member variable.

    Kuphryn

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Classes and Global Functions
    By d_heyzie in forum C++ Programming
    Replies: 4
    Last Post: 04-17-2007, 08:57 PM
  2. Declaring classes in global space
    By Rune Hunter in forum C++ Programming
    Replies: 12
    Last Post: 10-12-2005, 03:46 PM
  3. Global Variables, include files and classes
    By sharpstones in forum C++ Programming
    Replies: 1
    Last Post: 07-12-2005, 11:06 AM
  4. Global Classes
    By Death_Wraith in forum C++ Programming
    Replies: 3
    Last Post: 03-12-2004, 07:12 AM
  5. global classes?????
    By werdy666 in forum C++ Programming
    Replies: 1
    Last Post: 05-18-2002, 12:20 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21