Thread: 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 09:06:11
|
Are you saying that you will create objects of the class, named Dummies, Nerds, and BadBoys and limit their access? I might suggest using overloaded constructors and setting a member variable (a bool) to TRUE when used. For example, you have three overloaded constructors. any (DummyAccess = true); any (DummyAccess = true, NerdAccess = true); any (DummyAccess = true, NerdAccess = true, BadBoysAccess = true); Then in the member functions void any::very_important_func3( any &ConstructedObject ) { if (ConstructedObject.NerdAccess != true) { return 0; // escape from the function } //... Do something } What about that? >From: André Macário Barros <ama...@uo...> >To: Dev-C++ Mailing List <dev...@li...> >Subject: [Dev-C++] Off:Classes Access Restrictions >Date: Mon, 28 Oct 2002 23:06:15 -0200 > >Gentelmen, > > Sorry about the off-topic question, but let me know if you can help: > > 1. Consider the following Class > Class any{ > public: > any (int x=0, int y=0, int z=0); > void dummy_func1(); > void not_so_dummy_func2(); > void very_important_func3(); > void only_for_bad_boys_func4(); > private: > int x; > int y; > int z; > }; > > 2. Let suppose 3 different groups of users (supose programmers): > "The dummies", "The Nerds", and "The Bad Boys" > > 3. I want to restrict the access to the public functions by group, >that is, dummies programs only accessing func1, nerds programs accessing >func1 to func3, and badboys programs accessing all the functions; > > 4. Is it possible do this, step 3, in C++? > > 5. If item 4 is possible, is it possible in Dev-C++? How? > >Regards >André > > > > > > >------------------------------------------------------- >This sf.net email is sponsored by:ThinkGeek >Welcome to geek heaven. >http://thinkgeek.com/sf >_______________________________________________ >Dev-cpp-users mailing list >Dev...@li... >TO UNSUBSCRIBE: http://www.noicys.cjb.net/devcpp/ub.htm >https://lists.sourceforge.net/lists/listinfo/dev-cpp-users _________________________________________________________________ Unlimited Internet access for only $21.95/month. Try MSN! http://resourcecenter.msn.com/access/plans/2monthsfree.asp |
From: Daniel G. <sp...@ho...> - 2002-10-29 12:26:35
|
Slow up a second, "they" are going to be importing your class and creating instances of it? Make sure everything is documented! lol I think the premise of what we have so far is sound, though I believe my method of overloading the constructors with member variables initialised to true or false will work better than a string as you can combine the variables to create a new kind of object. 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" Am I making sense anyone??? >From: André Macário Barros <ama...@uo...> >To: Dev-C++ Mailing List <dev...@li...> >Subject: Re: [Dev-C++] Off:Classes Access Restrictions >Date: Tue, 29 Oct 2002 09:15:05 -0200 > >Have no preference. But I could say that it would be better the "dummies" >and >"nerds" even don't know that they could make "more things" using the class >any. Compile time maybe? > >Regards >André > >Per Westermark wrote: > > > Should the access restriction be made at compile time or at run time? > > > > /Per W > > > > On Mon, 28 Oct 2002, André Macário Barros wrote: > > > > > Gentelmen, > > > > > > Sorry about the off-topic question, but let me know if you can >help: > > > > > > 1. Consider the following Class > > > Class any{ > > > public: > > > any (int x=0, int y=0, int z=0); > > > void dummy_func1(); > > > void not_so_dummy_func2(); > > > void very_important_func3(); > > > void only_for_bad_boys_func4(); > > > private: > > > int x; > > > int y; > > > int z; > > > }; > > > > > > 2. Let suppose 3 different groups of users (supose programmers): > > > "The dummies", "The Nerds", and "The Bad Boys" > > > > > > 3. I want to restrict the access to the public functions by group, > > > that is, dummies programs only accessing func1, nerds programs >accessing > > > func1 to func3, and badboys programs accessing all the functions; > > > > > > 4. Is it possible do this, step 3, in C++? > > > > > > 5. If item 4 is possible, is it possible in Dev-C++? How? > > > > > > Regards > > > André > > > > > > > > > > > > > > > > > > > > > ------------------------------------------------------- > > > This sf.net email is sponsored by:ThinkGeek > > > Welcome to geek heaven. > > > http://thinkgeek.com/sf > > > _______________________________________________ > > > Dev-cpp-users mailing list > > > Dev...@li... > > > TO UNSUBSCRIBE: http://www.noicys.cjb.net/devcpp/ub.htm > > > https://lists.sourceforge.net/lists/listinfo/dev-cpp-users > > > > > > >------------------------------------------------------- >This sf.net email is sponsored by:ThinkGeek >Welcome to geek heaven. >http://thinkgeek.com/sf >_______________________________________________ >Dev-cpp-users mailing list >Dev...@li... >TO UNSUBSCRIBE: http://www.noicys.cjb.net/devcpp/ub.htm >https://lists.sourceforge.net/lists/listinfo/dev-cpp-users _________________________________________________________________ Unlimited Internet access for only $21.95/month. Try MSN! http://resourcecenter.msn.com/access/plans/2monthsfree.asp |
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/ |
From: Abhijit S. <mu...@gm...> - 2002-10-29 12:58:46
|
There was an error in my last message: > class FooNerd : public FooNerd That would be class FooNerd : public FooParent Sorry. ___________________________________________________________ Abhijit Shylanath E-mail: mu...@gm... || ibr...@bi... Web-site: http://mudeth.tripod.com/ |
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 |
From: B. <ama...@uo...> - 2002-10-29 17:41:15
|
Yes, perfect both methods and the solutions suggested. Thank you. The cla= ss side, that is, when the access to the fuction members of the class is made, it is we= ll defined. Now I'm thinking in a way to discover whose program is accessing them (th= e classes). In a Unix world I could check the gid and discover which kind of user pro= gram is requesting it. And in a Win environment? Are you understanding now? How can, in a run-time mode, I can check this = access Regards Andr=E9 =3D=3D=3D Daniel Glenfield wrote: > 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...u= rceforge.net> > >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 =3D true, NerdAccess =3D true= ) > > > and the function will not care what the object is named, it will ju= st > >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 accessib= le 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 ha= ve > >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() =3D 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 |
From: Carlos d. M. <cg...@wo...> - 2002-10-29 11:28:40
|
Or add a variable which says if you're nerd, a bad boy or a dummy, give i= t a value in the constructor, then each of those functions check first the va= lue of that variable, if it is what it is for it continues working,if not it ret= urns with a message, or not, or generates an exception. Daniel Glenfield escribi=F3: > Are you saying that you will create objects of the class, named Dummies= , > Nerds, and BadBoys and limit their access? > > I might suggest using overloaded constructors and setting a member vari= able > (a bool) to TRUE when used. For example, you have three overloaded > constructors. > > any (DummyAccess =3D true); > any (DummyAccess =3D true, NerdAccess =3D true); > any (DummyAccess =3D true, NerdAccess =3D true, BadBoysAccess =3D true)= ; > > Then in the member functions > > void any::very_important_func3( any &ConstructedObject ) > { > if (ConstructedObject.NerdAccess !=3D true) > { > return 0; // escape from the function > } > //... Do something > } > > What about that? > > >From: Andr=E9 Mac=E1rio Barros <ama...@uo...> > >To: Dev-C++ Mailing List <dev...@li...> > >Subject: [Dev-C++] Off:Classes Access Restrictions > >Date: Mon, 28 Oct 2002 23:06:15 -0200 > > > >Gentelmen, > > > > Sorry about the off-topic question, but let me know if you can hel= p: > > > > 1. Consider the following Class > > Class any{ > > public: > > any (int x=3D0, int y=3D0, int z=3D0); > > void dummy_func1(); > > void not_so_dummy_func2(); > > void very_important_func3(); > > void only_for_bad_boys_func4(); > > private: > > int x; > > int y; > > int z; > > }; > > > > 2. Let suppose 3 different groups of users (supose programmers): > > "The dummies", "The Nerds", and "The Bad Boys" > > > > 3. I want to restrict the access to the public functions by group, > >that is, dummies programs only accessing func1, nerds programs accessi= ng > >func1 to func3, and badboys programs accessing all the functions; > > > > 4. Is it possible do this, step 3, in C++? > > > > 5. If item 4 is possible, is it possible in Dev-C++? How? > > > >Regards > >Andr=E9 > > > > > > > > > > > > > >------------------------------------------------------- > >This sf.net email is sponsored by:ThinkGeek > >Welcome to geek heaven. > >http://thinkgeek.com/sf > >_______________________________________________ > >Dev-cpp-users mailing list > >Dev...@li... > >TO UNSUBSCRIBE: http://www.noicys.cjb.net/devcpp/ub.htm > >https://lists.sourceforge.net/lists/listinfo/dev-cpp-users > > _________________________________________________________________ > Unlimited Internet access for only $21.95/month. Try MSN! > http://resourcecenter.msn.com/access/plans/2monthsfree.asp > > ------------------------------------------------------- > This sf.net email is sponsored by:ThinkGeek > Welcome to geek heaven. > http://thinkgeek.com/sf > _______________________________________________ > Dev-cpp-users mailing list > Dev...@li... > TO UNSUBSCRIBE: http://www.noicys.cjb.net/devcpp/ub.htm > https://lists.sourceforge.net/lists/listinfo/dev-cpp-users |
From: B. <ama...@uo...> - 2002-10-29 12:12:09
|
Thank you, Sir, but what is written in their main.cpp file? Remember: tha= t groups, dummies, nerds, and badboys, are only symbolic names. There is no= thing set up telling for the class that one or other is accessing it. Regards, Andr=E9 =3D=3D=3D Daniel Glenfield wrote: > Are you saying that you will create objects of the class, named Dummies= , > Nerds, and BadBoys and limit their access? > > I might suggest using overloaded constructors and setting a member vari= able > (a bool) to TRUE when used. For example, you have three overloaded > constructors. > > any (DummyAccess =3D true); > any (DummyAccess =3D true, NerdAccess =3D true); > any (DummyAccess =3D true, NerdAccess =3D true, BadBoysAccess =3D true)= ; > > Then in the member functions > > void any::very_important_func3( any &ConstructedObject ) > { > if (ConstructedObject.NerdAccess !=3D true) > { > return 0; // escape from the function > } > //... Do something > } > > What about that? > > >From: Andr=E9 Mac=E1rio Barros <ama...@uo...> > >To: Dev-C++ Mailing List <dev...@li...> > >Subject: [Dev-C++] Off:Classes Access Restrictions > >Date: Mon, 28 Oct 2002 23:06:15 -0200 > > > >Gentelmen, > > > > Sorry about the off-topic question, but let me know if you can hel= p: > > > > 1. Consider the following Class > > Class any{ > > public: > > any (int x=3D0, int y=3D0, int z=3D0); > > void dummy_func1(); > > void not_so_dummy_func2(); > > void very_important_func3(); > > void only_for_bad_boys_func4(); > > private: > > int x; > > int y; > > int z; > > }; > > > > 2. Let suppose 3 different groups of users (supose programmers): > > "The dummies", "The Nerds", and "The Bad Boys" > > > > 3. I want to restrict the access to the public functions by group, > >that is, dummies programs only accessing func1, nerds programs accessi= ng > >func1 to func3, and badboys programs accessing all the functions; > > > > 4. Is it possible do this, step 3, in C++? > > > > 5. If item 4 is possible, is it possible in Dev-C++? How? > > > >Regards > >Andr=E9 > > > > > > > > > > > > > >------------------------------------------------------- > >This sf.net email is sponsored by:ThinkGeek > >Welcome to geek heaven. > >http://thinkgeek.com/sf > >_______________________________________________ > >Dev-cpp-users mailing list > >Dev...@li... > >TO UNSUBSCRIBE: http://www.noicys.cjb.net/devcpp/ub.htm > >https://lists.sourceforge.net/lists/listinfo/dev-cpp-users > > _________________________________________________________________ > Unlimited Internet access for only $21.95/month. Try MSN! > http://resourcecenter.msn.com/access/plans/2monthsfree.asp |