473,406 Members | 2,713 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,406 software developers and data experts.

Inaccessible method

MarkoKlacar
296 Expert 100+
Hi AlI,

I have a class called Rectangle that contains a public method:
Expand|Select|Wrap|Line Numbers
  1. bool contains(int x, int y);
I have a nother class called Components that is a subclass of Rectangle.

From a totally different class, Compund, I now want to loop through a vector<Component*> and call the method contains with the appropriate arguments.

I get an error telling me:

Expand|Select|Wrap|Line Numbers
  1. ../Rectangle.h:11: `bool Rectangle::contains(int, int)' is inaccessible
  2. ../Compound.cpp:43: within this context
  3.  
It's probably real obvious, I'm not that good with c++.

Any ideas?

Cheers
May 6 '08 #1
3 2414
Airslash
221 100+
Hi AlI,

I have a class called Rectangle that contains a public method:
Expand|Select|Wrap|Line Numbers
  1. bool contains(int x, int y);
I have a nother class called Components that is a subclass of Rectangle.

From a totally different class, Compund, I now want to loop through a vector<Component*> and call the method contains with the appropriate arguments.

I get an error telling me:

Expand|Select|Wrap|Line Numbers
  1. ../Rectangle.h:11: `bool Rectangle::contains(int, int)' is inaccessible
  2. ../Compound.cpp:43: within this context
  3.  
It's probably real obvious, I'm not that good with c++.

Any ideas?

Cheers
Ok, from my head and on the fly:

Expand|Select|Wrap|Line Numbers
  1. class Rectangle {
  2. public:
  3. virtual bool contains(int, int);
  4. }
  5.  
Expand|Select|Wrap|Line Numbers
  1. class Component : public Rectangle {
  2. public:
  3. bool contains(int, int);
  4.  
With this your component inherits from rectangle, and overwrites the function.

An another approach is to insert the rectangle class as a datamember in your Component class, and give your Component class a method contains(int, int) that calls the contains method of your datamember
May 6 '08 #2
MarkoKlacar
296 Expert 100+
Hi,

Thanks for the reply. I created a method inside Component that calls the Rectangle::contains(int,int)...

Thanks!
May 6 '08 #3
Banfa
9,065 Expert Mod 8TB
Thanks for the reply. I created a method inside Component that calls the Rectangle::contains(int,int)...
That shouldn't be required unless Component::contains actually has different functionality to Rectangle::contains you should be able to declare it as

Expand|Select|Wrap|Line Numbers
  1. class Rectangle 
  2. {
  3. public:
  4.     virtual bool contains(int, int);
  5. }
  6.  
  7. class Component : public Rectangle 
  8. {
  9. }
  10.  
and be able to call contains from a object of type Component. I suspect in your first implementation that you left out the public keyword when declaring Component as a subclass of Rectangle.
May 6 '08 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Larry | last post by:
I have a VB background and am developing a new windows app in Csharp. I'm getting the error. 'inaccessible due to its protection level' I've added a TextBox1 and a Button1 to a form. I...
1
by: Thomas Barnet-Lamb | last post by:
I was wondering if anyone could give me some help with the following. Consider the code snippet: struct qqq{typedef qqq* pointer;}; template<class al> struct foo : public al { template...
2
by: Irfan | last post by:
hi, In C#.Net, if i have a form1 and i want to access one of the controls of form2(eg a label) from Form1, it gives an error. (Label1 is Inaccessible, due to its protection level) However, i...
5
by: Iain | last post by:
Hi All I have the code below (Using Delphi 2006 Developer to create an C# ASP.Net page to update a simple database table. When the page is fired I get the following error message ...
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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
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
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
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,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.