Wrox Programmer Forums
Go Back   Wrox Programmer Forums > .NET > Other .NET > General .NET
| 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 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
  #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!

  #2 (permalink)  
Old May 20th, 2004, 09:41 AM
Imar's Avatar
Wrox Author
Points: 70,322, Level: 100
Points: 70,322, Level: 100 Points: 70,322, Level: 100 Points: 70,322, Level: 100
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 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?
  #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.



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





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