473,503 Members | 2,066 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

why member inaccessible?

public class BaseDALC
{
//Don't allow instantiation
private BaseDALC() // To compile properly, I had to change this to
"protected"
{ }
}
....
public class StatisticsDALC : BaseDALC
{
}

error CS0122: 'AirportInformation.DAL.BaseDALC.BaseDALC()' is inaccessible
due to its protection level. Why the compile problem? Does inheritance
require accessibility to the base class constructor? Thanks! --Marty
Nov 15 '05 #1
6 2729
you cannot inherit a class with a private constructor.. as the inheriting
class cannot call any of its methods..
"Marty McDonald" <mc******@wsdot.wa.gov> wrote in message
news:ug**************@TK2MSFTNGP11.phx.gbl...
public class BaseDALC
{
//Don't allow instantiation
private BaseDALC() // To compile properly, I had to change this to
"protected"
{ }
}
...
public class StatisticsDALC : BaseDALC
{
}

error CS0122: 'AirportInformation.DAL.BaseDALC.BaseDALC()' is inaccessible
due to its protection level. Why the compile problem? Does inheritance
require accessibility to the base class constructor? Thanks! --Marty

Nov 15 '05 #2
Thanks! Is that true even if the base class will have nothing but static
members?

"Syanide" <me@knowhere.com> wrote in message
news:u3*********************@news-text.cableinet.net...
you cannot inherit a class with a private constructor.. as the inheriting
class cannot call any of its methods..
"Marty McDonald" <mc******@wsdot.wa.gov> wrote in message
news:ug**************@TK2MSFTNGP11.phx.gbl...
public class BaseDALC
{
//Don't allow instantiation
private BaseDALC() // To compile properly, I had to change this to
"protected"
{ }
}
...
public class StatisticsDALC : BaseDALC
{
}

error CS0122: 'AirportInformation.DAL.BaseDALC.BaseDALC()' is inaccessible due to its protection level. Why the compile problem? Does inheritance
require accessibility to the base class constructor? Thanks! --Marty


Nov 15 '05 #3
Marty McDonald wrote:
public class BaseDALC
{
//Don't allow instantiation
private BaseDALC() // To compile properly, I had to change this to
"protected"
{ }
}
...
public class StatisticsDALC : BaseDALC
{
}

error CS0122: 'AirportInformation.DAL.BaseDALC.BaseDALC()' is inaccessible
due to its protection level. Why the compile problem? Does inheritance
require accessibility to the base class constructor? Thanks! --Marty


Since you didn't specify a constructor for StatisticsDALC, the compiler
provides a default constructor of the form:

public StatisticsDALC(): base() {}

(See MSDN C# Specification section 10.10.4)

So the constructor for the base class must be accessible.

Note that defining a constructor explicitly does not get around this -
some constructor in the base class needs to be called, however if you
explicitly define a constructor for your class, you can control which
constructor gets called (which still needs to be accessible, and
therefore cannot be private).

See the MSDN C# Spec 10.10.1 for details.

--
mikeb
Nov 15 '05 #4

Hi Marty,

Thank you for posting in the community! My name is Jeffrey, and I will be
assisting you on this issue.

================================================== ===
I agree with mikeb's reply.

If a class contains no instance constructor declarations, a default
instance constructor is automatically provided. That default constructor
simply invokes the parameterless constructor of the direct base class.
Because your DIRECT base class constructor is inaccessible, If the direct
base class does not have an accessible parameterless instance constructor,
a compile-time error occurs.

More detailed information, please refer to:
http://msdn.microsoft.com/library/de...us/csspec/html
/vclrfcsharpspec_10_10_4.asp

Also, your inherited class's constructor will invoke the direct base
class's constructor. All instance constructors (except those for class
object) implicitly include an invocation of another instance constructor
immediately before the constructor-body.
An instance constructor initializer of the form base(argument-listopt)
causes an instance constructor from the direct base class to be invoked.
The set of candidate instance constructors consists of all accessible
instance constructors contained in the direct base class. If this set is
empty, or if a single best instance constructor cannot be identified, a
compile-time error occurs.

For more information, please refer to:
http://msdn.microsoft.com/library/de...us/csspec/html
/vclrfcsharpspec_10_10_1.asp

================================================== ==
Please apply my suggestion above and let me know if it helps resolve your
problem.

Thank you for your patience and cooperation. If you have any questions or
concerns, please feel free to post it in the group. I am standing by to be
of assistance.
Have a nice day!!

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.

Nov 15 '05 #5
Thanks for the information. I looked at the C# spec and read section 10.10.
Most applicable to my issue was section 10.10.5:
10.10.5 Private constructors
When a class declares only private instance constructors, it is not possible
for other classes to derive from the class or create instances of the class
(an exception being classes nested within the class). Private instance
constructors are commonly used in classes that contain only static
members....

Thanks everyone, you helped resolve the issue!
Nov 15 '05 #6

Hi Marty,

Thanks for your feedback.

I am glad our reply makes sense to you.

Yes, actually, you just do Private Constructor in your code, so you can not
inherited this class.

If you have any further concern, please feel free to post in this group. I
will work with you.

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.

Nov 15 '05 #7

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

Similar topics

1
1653
by: none | last post by:
Hi, I have a base class with a pointer-to-member function variable. Then I have a derived class that needs to use that variable to call a member function (with the same arguments and return value...
7
3495
by: spam | last post by:
The following code does not compile: class X {}; class Y : private X {}; class Z : public Y { public: Z(X&) {} // problem here
8
8422
by: Ganesh Kundapur | last post by:
Hi all, struct test { static int x; }X; main() { X.x = 100; }
2
1816
by: Christoph Boget | last post by:
Let's take the following class: class MyClass { private int privateVar; public int PublicVar { get { return privateVar; } } public MyClass() {}
1
3105
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...
6
4391
by: Bill Rubin | last post by:
The following code snippet shows that VC++ 7.1 correctly compiles a static member function invocation from an Unrelated class, since this static member function is public. I expected to compile the...
1
3452
by: =?Utf-8?B?d3BjbWFtZQ==?= | last post by:
I got the following code public ref class A { value struct PrivateType sealed { Int32 id; }; public: ref struct B abstract sealed { static const PrivateType x = {1}; static const PrivateType...
15
2378
by: Victor Bazarov | last post by:
Hello, Take a look at this program: ----------------------------------- class B { B(const B&); B& operator=(const B&); public: B(int);
2
1159
by: tomas | last post by:
Hi. I'm working with a C++ framework that has something like this: class A { protected: virtual void init(); virtual void run(); // rest of the class ....
0
7205
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7348
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...
1
7006
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
7467
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
4685
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3175
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
1519
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
744
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
397
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.