Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > C# and C > C# 1.0 > C#
Password Reminder
Register
| FAQ | Members List | Calendar | 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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
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
Reply With Quote
  #2 (permalink)  
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)


Reply With Quote
  #3 (permalink)  
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
Reply With Quote
  #4 (permalink)  
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

Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


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



All times are GMT -4. The time now is 09:39 PM.


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.