🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: git.general
Article #36

Re: Cool REGEDIT Program: FREE

#36
From: Kenneth C Stahl
Date: Fri, 09 Nov 2001 12:00
52 lines
3077 bytes
Tim Faircloth wrote:

> In the words of the imortal Tae:
> > I smell a loaded question. :-)  There are times when a global variable is
> > necessary, no?  I'm a CmpE major, so I haven't had the full CS treatment..
> > so I'll leave this to a CS major.. somebody? hehe
>
> well gee... you *could* declare it in main and just pass it to every
> single function you call...
>
> /tim
> --
> Do not go silent into that good night.
> Rage, rage against the dying of the light.
> -Dylan Thomas

There is a much easier solution.


#include <whatever header files>

class MyClass {
    public:
    MyClass(void){
        MyVar = 999;
        MyAction();
    }

    ~MyClass {
        cout << "Good-bye" << endl;
    }
    private:
        int MyVar = 0;
        void MyAction(){
            cout << "MyVar =" << MyVar << endl;
        }
}

int main(int argc, char **argv){
    MyClass ThisClass;
    exit(0);
}


The trick is that the constructor calls the function MyAction() which
then goes off and does everything necessary for the required actions of
the program. No need for global variables because any variable used in
the program would be encapsulated within the class. Within main(), the
instantiation of the class would cause the constructor to fire and when
execution falls off the end of the constructor, execution would return
to main and the program exits. Heck, I wouldn't even actually need the
exit(0) since that is the default.
Technical Details
Message-ID: <3BEBC727.674CF859@Unforgetable.com>
Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!newsfeed.stanford.edu!news-spur1.maxwell.syr.edu!news.maxwell.syr.edu!feed2.news.rcn.net!rcn!chnws02.mediaone.net!jxnws01!typhoon.jacksonville.mediaone.net.POSTED!not-for-mail
References: <3bedc6b0.81798692@flashnews.prodigy.net> <3be93046.11254794@netnews.worldnet.att.net> <9sbg6o$8f9$1@news-int.gatech.edu> <3BE9C00E.94F09EA1@Unforgetable.com> <9scq25$5og$1@news-int.gatech.edu> <3BE9F9E8.CA5BC342@Unforgetable.com> <9sd5g5$dv8$1@news-int.gatech.edu> <Xns9153180F1A0B4gte543eGATECH@130.207.244.116> <slrn9ukcem.g1m.zendude@helsinki.cc.gatech.edu> <Xns91531B23AE90Fgte543eGATECH@130.207.244.116> <slrn9ukutv.iq1.nova20@nova20.resnet.gatech.edu>

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: 10e1e4,46614be0108095db
X-Google-Attributes: gid10e1e4,public
X-Google-Thread: 108158,46614be0108095db
X-Google-Attributes: gid108158,public
X-Google-ArrivalTime: 2001-11-09 04:23:42 PST
Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!newsfeed.stanford.edu!news-spur1.maxwell.syr.edu!news.maxwell.syr.edu!feed2.news.rcn.net!rcn!chnws02.mediaone.net!jxnws01!typhoon.jacksonville.mediaone.net.POSTED!not-for-mail
Message-ID: <3BEBC727.674CF859@Unforgetable.com>
From: Kenneth C Stahl <BlueSax@Unforgetable.com>
Reply-To: BlueSax@Unforgetable.com
X-Mailer: Mozilla 4.78 [en] (Win98; U)
X-Accept-Language: en
MIME-Version: 1.0
Newsgroups: git.general,atl.general
Subject: Re: Cool REGEDIT Program:  FREE
References: <3bedc6b0.81798692@flashnews.prodigy.net> <3be93046.11254794@netnews.worldnet.att.net> <9sbg6o$8f9$1@news-int.gatech.edu> <3BE9C00E.94F09EA1@Unforgetable.com> <9scq25$5og$1@news-int.gatech.edu> <3BE9F9E8.CA5BC342@Unforgetable.com> <9sd5g5$dv8$1@news-int.gatech.edu> <Xns9153180F1A0B4gte543eGATECH@130.207.244.116> <slrn9ukcem.g1m.zendude@helsinki.cc.gatech.edu> <Xns91531B23AE90Fgte543eGATECH@130.207.244.116> <slrn9ukutv.iq1.nova20@nova20.resnet.gatech.edu>
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
Lines: 57
Date: Fri, 09 Nov 2001 12:00:40 GMT
NNTP-Posting-Host: 24.165.114.78
X-Complaints-To: abuse@mediaone.net
X-Trace: typhoon.jacksonville.mediaone.net 1005307240 24.165.114.78 (Fri, 09 Nov 2001 07:00:40 EST)
NNTP-Posting-Date: Fri, 09 Nov 2001 07:00:40 EST