Wrox Programmer Forums
Go Back   Wrox Programmer Forums > C# and C > C# 1.0 > C#
| Search | Today's Posts | Mark Forums Read
C# Programming questions specific to the Microsoft C# language. See also the forum Beginning Visual C# to discuss that specific Wrox book and code.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the C# section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old July 16th, 2004, 02:29 AM
Registered User
 
Join Date: Jul 2004
Location: , , .
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default classes :: base class is inaccessible ....

Hello,

i'am a beginner in c# ... having a few problems with classes

Cld u pls help me out

code is as follows

--------------------------------------------------------------------
Error : Base Class is inaccessible due to it's protection level
--------------------------------------------------------------------

public class MybaseClass
{
    private MyBaseClass()
    {
    }

    public MyBaseClass(string temp)
    {
        Console.WriteLine("non-dafault constructor of base class called : {0}", temp);
    }
}

public class MyDerivedClass : MyBaseClass
{
    private MyDerivedClass()
    {
    }

    public MyDerivedClass(string temp): base("default base name")
    {
        Console.WriteLine("non-default constructor of derived class : {0}", temp);
    }
}

================================================== ===================
static void Main()
{
    MyDerivedClass myDerObj = new MyDerivedClass("temp");
}
================================================== ===================

------------------------------------------------
kaliste
 
Old July 16th, 2004, 03:36 AM
Friend of Wrox
 
Join Date: Jul 2004
Location: Tehran, , Iran.
Posts: 623
Thanks: 0
Thanked 1 Time in 1 Post
Default

when you use
MyDerivedClass myDerObj = new MyDerivedClass();
in Main();you are constructing your class with default constructor that you declare as private make your default constructor public or give parameter to your constructor(for using overload methods)
!!!in yor code I didn't see any derivation
(public class MyDerivedClass :MybaseClass is right)


 
Old July 16th, 2004, 04:10 AM
Registered User
 
Join Date: Jul 2004
Location: , , .
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default

thnx for the reply mehdi

did a few typos there while posting.... my apologies

MyDerivedClass : MyBaseClass

did use MyDerivedClass myDerObj = new MyDerivedClass("derived");

still the same error




------------------------------------------------
kaliste
 
Old July 16th, 2004, 04:56 AM
Friend of Wrox
 
Join Date: Jul 2004
Location: Tehran, , Iran.
Posts: 623
Thanks: 0
Thanked 1 Time in 1 Post
Default

Hi again
Kaliste
in your derived class you have a default constructer like below
---------------
private MyDerivedClass()
    {
    }
--------------
but compiler compile it as below
---------------
private MyDerivedClass() :base()
    {
    }
--------------
that means your default constructor in the drived class uses default constructer
in base class(for loading methods and .. in base class) and because you declare your default constructer as private
it is inaccessible and the error occures
you should declare your default constructer in baseclass as public or protected





Similar Threads
Thread Thread Starter Forum Replies Last Post
How the Virtual base classes are works? pushpa C# 2005 1 October 3rd, 2007 03:11 AM
Base Class for Code-Behind Problem groupmatch BOOK: ASP.NET Website Programming Problem-Design-Solution 3 September 8th, 2004 05:06 AM
base class inheritance krunch97 VB.NET 2002/2003 Basics 6 April 23rd, 2004 11:48 AM
Page_Load override with base page class nebrown1 BOOK: ASP.NET Website Programming Problem-Design-Solution 1 August 31st, 2003 04:45 AM
Help with DBObject base class projectedNexus BOOK: ASP.NET Website Programming Problem-Design-Solution 1 August 12th, 2003 06:36 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.