Re: Global Variable or Not

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance

From: Sigurd Stenersen (sigurds_at_utvikling.com)
Date: 09/30/04


Date: Thu, 30 Sep 2004 16:42:53 +0200

Macca wrote:
> In my application i have one class,Class A, which as the app is being
> run collects diagnostic information throughout the day and stores it
> in a vector.
>
> I have another class, Class B, that at the end of the day will take
> the contents of this vector, that has been built up over the day, and
> produces some excel reports from it.
>
> The problem i am having is how Class B accesses the vector that Class
> A is using.
>
> There is no relationship between the 2 classes.
> One way would be to declare the vector as a global variable that the
> two classes can access.

Which class does the vector belong to ? That is, who owns it ?

If A owns it and only A and B should be allowed to access it, you could make
it a protected member of A and make B a friend of A.

If neither A nor B own it, you could make a separate owner class C that
allows only A and B access to it.

Anyhow, just make something that works and move on to more important
issues...

-- 
Sigurd
http://utvikling.com


Relevant Pages

  • Global Variable or Not
    ... In my application i have one class,Class A, which as the app is being run ... collects diagnostic information throughout the day and stores it in a ...
    (microsoft.public.vc.mfc)
  • Re: Global Variable or Not
    ... >In my application i have one class,Class A, which as the app is being run ... >collects diagnostic information throughout the day and stores it in a ... I suggest not allowing A or B to use the pointers to access the vector ...
    (microsoft.public.vc.mfc)
  • Re: Locator app with global mapping?
    ... | Anyone know of a good PHP-based store/dealer locator app that can handle ... supply an address that you feed to google maps. ... get the long/lat of that address. ... stores where the top n stores are nearest the long/lat of the user supplied ...
    (alt.php)
  • Re: Locator app with global mapping?
    ... | Anyone know of a good PHP-based store/dealer locator app that can handle ... supply an address that you feed to google maps. ... get the long/lat of that address. ... stores where the top n stores are nearest the long/lat of the user supplied ...
    (alt.php)
  • Re: Lock Dialog in position
    ... > Macca wrote: ... >> The problem i have is that my app can be dragged around the screen by ... >> clicking and dragging the title bar. ... What Scott suggests, trapping WM_NCHITTEST does not appear to have side ...
    (microsoft.public.vc.mfc)