Re: [Dev-C++] Off:Classes Access Restrictions
Open Source C & C++ IDE for Windows
Brought to you by:
claplace
|
From: Daniel G. <sp...@ho...> - 2002-10-29 13:53:47
|
I'd considered derived classes as a solution, but I think perhaps the
exercise (it sounds like one) involves creating a portable class - one that
can be plugged in to a project.
The variables specified could have been anything, so we're not sure on
whether our solutions are going to work or not. The functions are not
specified so they could do anyhting. I thought setting access via the
constructors would work better. After all, if the object was to derive the
class into child classes the exercise would have said so surely?
>From: "Abhijit Shylanath" <mu...@gm...>
>To: "Daniel Glenfield"
><sp...@ho...>,<ama...@uo...>,<dev...@li...>
>Subject: Re: [Dev-C++] Off:Classes Access Restrictions
>Date: Tue, 29 Oct 2002 18:26:02 +0530
>
>Greets, everyone.
>
> > So a superdummy could be (DummyAccess = true, NerdAccess = true)
> > and the function will not care what the object is named, it will just
>see
> > the value of the variable for NerdAccess. If it were a string, the
>function
> > would have to be rewritten to accomodate "superdummy"
>
>I came in late (I'd disabled my mail delivery for sometime), so I may not
>be
>talking about what you're talking about. But according to what Daniel is
>talking about, someone wants a class, some parts of which are accessible to
>some dudes, other parts to other dudes. His method makes sense. Also, it
>should be more efficient than using strings (less time to compare or
>check).
>You could also modify the method to use a flag, like
>
> Constructor(int access_mode);
>
>which could be a combination of
>
> #define FOO_MODE_DUMMY 0x01
> #define FOO_MODE_NERD 0x02
>
>like so:
>
> Constructor(FOO_MODE_DUMMY | FOO_MODE_NERD);
>
>Within the methods, checking would be like so:
>
> if(access_mode & FOO_MODE_NERD)
> {
> // Do nerdy stuff
> }
>
>But this method is run-time checking, and you wouldn't know what to do if a
>dummy tries to access a nerd-only-function. Error-message? Drop to OS?
>Wouldn't it be better if there were compile-time errors? Yes, so we have
>the
>new and improved C++-style DERIVED CLASSES! Yes, with one simple wave of
>the
>hand... never mind... how's this?
>
>class FooParent
>{
> public:
> FooParent();
> ~FooParent();
>
> virtual int WhichFoo() = 0;
>
> private:
> int num_stuff;
>};
>
>class FooDummy : public FooParent
>{
> /* blah */
>};
>
>class FooNerd : public FooNerd
>{
> /* different blah */
>};
>
>Was this what was asked?
>
>___________________________________________________________
>
>Abhijit Shylanath
>
>E-mail: mu...@gm... || ibr...@bi...
>Web-site: http://mudeth.tripod.com/
_________________________________________________________________
Surf the Web without missing calls! Get MSN Broadband.
http://resourcecenter.msn.com/access/plans/freeactivation.asp
|