Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > .NET > Other .NET > General .NET
Password Reminder
Register
Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
General .NET For general discussion of MICROSOFT .NET topics that don't fall within any of the other .NET forum subcategories or .NET language forums.  If your question is specific to a language (C# or Visual Basic) or type of application (Windows Forms or ASP.Net) try an applicable forum category. ** PLEASE BE SPECIFIC WITH YOUR QUESTION ** When posting here, provide details regarding the Microsoft .NET language you are using and/or what type of application (Windows/Web Forms, etc) you are working in, if applicable to the question. This will help others answer the question without having to ask.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the General .NET 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 May 20th, 2004, 09:26 AM
Authorized User
 
Join Date: Sep 2003
Location: , , .
Posts: 93
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via AIM to flyin
Default Inheritance problem

Hello Everyone i'm having trouble understand, rather not understanding why my "stuff" doesn't work correctly.

Tell me if you see anything incorrect here

Example:

Public MustInherit Class User
    Dim Private _iAccountID as integer

    Protected Sub New(ByVal _AccountID as Integer)
        _iAccountID = _AccountID
    End Sub

    Protected Property AccountID() As Integer
        Get
            Return _iAccountID
        End Get
        Set(ByVal Value As Integer)
            _iAccountID = Value
        End Set
    End Property
End Class

Public Class Child_User : Inherits User

    Public Sub new(ByVal _AccountID)
        MyBase.New(_AccountID)
    End Sub
End Class

.... In some .aspx file

Dim CUser as new Child_User(55)

// Here is the problem
CUser.AccountID = 95
// The Problem is that my intellisense does
// not bring up the protected property
// AccountID of the base class.
//Child_User is inherited from it
//so doesn't that mean
// that it inherits anything
//declared Public and protected?
// Maybe i'm not understanding
//inheritance in vb. I was
//under the assumption it is the
// same as in C++

I guess properties and methods of the base class
 have to be declared public if you
want to access them from an new instance of a
derived class?

Please HELP!

Reply With Quote
  #2 (permalink)  
Old May 20th, 2004, 09:41 AM
Imar's Avatar
Wrox Author
Points: 72,038, Level: 100
Points: 72,038, Level: 100 Points: 72,038, Level: 100 Points: 72,038, Level: 100
Activity: 100%
Activity: 100% Activity: 100% Activity: 100%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,080
Thanks: 80
Thanked 1,587 Times in 1,563 Posts
Default

Hi flyin,

You'll have to mark the property as Friend as well. Protected members are accessible in the current class and in the derived class only. So, inside the Child_User class you can access MyBase.AccountID, but not outside that derived class.

When you mark the property as Protected Friend, it's accessible in the base class, in any derived classes and in other classes in the same assembly:
Code:
Protected Friend Property AccountID() As Integer
  Get
    Return _iAccountID
  End Get
  Set(ByVal Value As Integer)
    _iAccountID = Value
  End Set
End Property
Was my post about User Controls useful to you??

Cheers,

Imar
---------------------------------------
Imar Spaanjaars
Everyone is unique, except for me.
While typing this post, I was listening to: The Sprawl by Sonic Youth (Track 3 from the album: Daydream Nation) What's This?
Reply With Quote
  #3 (permalink)  
Old May 20th, 2004, 10:55 AM
Authorized User
 
Join Date: Sep 2003
Location: , , .
Posts: 93
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via AIM to flyin
Default

hmmm yes yes yes, jeez, basic inheritance ya think i'd know that by now! Yes, the derived class doesn't have a public interface! Alright thanks imar.

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
inheritance problem kaos_frack BOOK: Professional JavaScript for Web Developers ISBN: 978-0-7645-7908-0 1 March 25th, 2007 09:28 AM
Problem With Inheritance jazzcatone ASP.NET 2.0 Basics 1 April 23rd, 2006 11:33 AM
c# inheritance bhohman C# 2 March 26th, 2004 01:47 PM
Vectors/inheritance problem hpy_gilmore8 C++ Programming 1 February 23rd, 2004 08:21 PM



All times are GMT -4. The time now is 02:15 PM.


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