473,396 Members | 1,804 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

access modifier in c++

In C++ any i can simulate some restricted access modifiers based on
association & inheritance?
eg,
class BombMaker{
private:
void makeAtomBomb(){
std::cout<<"making atom bomb\n";
}
int getSecretFormula()const{return 51;}
protected:
void makeRDX(){
std::cout<<"making RDX\n";
}
int getRDXFormula()const{return 101;}
std::vector<BombMaker*helpers;
public:
void makeFireCracker(){
std::cout<<"making firecrackers\n";
}
void makeAtomBombFor(BombMaker& m){
m.makeAtomBomb();
}
void stealFormula(BombMaker& o){
int formula = o.getSecretFormula();
}
};

here,
BombMaker* bad = new BombMaker();
BombMaker* notSoBad = new BombMaker();
bad->makeAtomBombFor(*notSoBad);/// i want this to work as now it
works. so another bomb maker can give the bad one to make a bomb for
him.
bad->stealFormula(*notSoBad);/// but bad one even can steal the
formula for the bomb through association with notSoBad. That should
not be allowed as the formula is only for personal use and is
dangerous for world. Can private be made exclusive so that association
is not allowed for private?
ie, essentially getSecretFormula() can only be used by the object
itself.

secondly,
i have a derived class,
class DestructiveBuddy : public BombMaker{
public:
void getFormula(BombMaker& o){//1
int formula = o.getRDXFormula();
}
void getFormulaFrom(DestructiveBuddy o){
int formula = o.getRDXFormula();
}
void acquireFormula(){
int formula = getRDXFormula();
}
void getFromHelpers(){//2
for(std::size_t i = 0; i< helpers.size();++i){
helpers[i]->getRDXFormula();
}
}
};
now is there any way to have a protected modifier which allows an
DestructiveBuddy to getFromula from a BombMaker also (as he himself is
a BombMaker) as in (1) along with other DestructiveBuddy's.
In the same way, an DestructiveBuddy object also want's all of the
helper which it has, to give the RDXFormula to him as all of them are
BombMaker and so is DestructiveBuddy himself, but not to anyone who is
not a BombMaker.
So unlike the previous case, where private through association is not
required, here protected through association is require.

Thanks

Jul 16 '08 #1
0 1632

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Dan Disney | last post by:
I have read conflicting information on the access scope of VB.Net class declarations when no access modifier is specified. MSDN library documentation states "Classes that do not specify an access...
3
by: N Khan via .NET 247 | last post by:
Hi, I know the usage of access modifier ?public? in DLL assembliesbut I am a bit puzzled that if let say I have a public class inan exe assembly then what purpose access modifier ?public?...
1
by: Ashkan Daie | last post by:
Hi All, Is there an internal access modifier in managed vc++ like vc#? Thanks, Ashkan
1
by: Mark Kamoski | last post by:
Hi-- Please help. What is the default access modifier value for a Sub or a Function when one has not explicitly been set. In MSDN, in "Access Types", it states... "If no access modifier...
3
by: Mr Newbie | last post by:
I am messing around with Web User Controls at present and (think) I have discovered the following. 1.) The identifier for the control in the code behind must match the ID for the control on the...
5
by: Harold Hsu | last post by:
Hi all, What's the default access type of a property declared in an interface? The one I'm looking at is IBindingList: Public Interface IBindingList .... ReadOnly Property AllowEdit As...
5
by: dost | last post by:
can u tell me the diffrence between...... private public and protected .........in........these.......which one...is access modifier....and which one..is specifier....... and....the diffrence...
3
by: RitualDave | last post by:
This compiles and runs successfully in VS2005: ref class A { private: ~A() { this->!A(); } // private! !A() { } // private! }; ....
9
by: JT | last post by:
Here is the overall structure I will be referring to: End-program ProvideWorkFlow.dll Forms and methods that properly manipulate calls to methods in AccessUtils AccessUtils (a web service)...
5
by: wpmccormick | last post by:
What is the cleanest way to gain access to object methods and properties across classes and files in the same namespace? Example: A form object frmForm in file frmForm.cs creates obj1 defined in...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.