Re: [Dev-C++] Off:Classes Access Restrictions
Open Source C & C++ IDE for Windows
Brought to you by:
claplace
|
From: Abhijit S. <mu...@gm...> - 2002-10-29 12:57:12
|
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/
|