Using Pointers in Contained Classes

This is a discussion on Using Pointers in Contained Classes within the C++ Programming forums, part of the General Programming Boards category; I would like to describe an example class hierarchy before I ask my question. I have an abstract class named ...

  1. #1
    Registered User
    Join Date
    Sep 2004
    Posts
    2

    Using Pointers in Contained Classes

    I would like to describe an example class hierarchy before I ask my question. I have an abstract class named Abstract. I have a class named UpperClass that was derived from Abstract. I have a class named LowerClass that is contained in UpperClass.

    I find that I am able to pass a Abstract* down to LowerClass through the constructors. However, if I am not able to dynamic_cast the Abstract* to UpperClass* in a LowerClass member function. My Visual C++ compiler won't let me do a #include "UpperClass.h" inside lower class. Why is this? Why will C++ let me use a Abstract* in LowerClass but not a UpperClass*? How can I get around this? I need to be able to do this in LowerClass: UpperClassPtr->SomeOtherDataNotInAbstract;

  2. #2
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,893
    What error do you get? What's the code that generates it? There's no reason why this should not be possible.
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

  3. #3
    Banned master5001's Avatar
    Join Date
    Aug 2001
    Location
    Visalia, CA, USA
    Posts
    3,685
    Actually, if I'm understanding correctly, he may be doing this wrong. Would you be a good sport and post your code?

  4. #4
    Registered User
    Join Date
    Sep 2004
    Posts
    2

    I cannot post my code

    I am unable to post my code. Later today I will write an example program that convays my C++ problem. Thanks for the responses.

  5. #5
    Banned master5001's Avatar
    Join Date
    Aug 2001
    Location
    Visalia, CA, USA
    Posts
    3,685
    No biggy not being able to show the actual code, an example of the problem is a-okay by me.

  6. #6
    Never Exist Hermitsky's Avatar
    Join Date
    Jul 2004
    Posts
    149
    abstract class? what is abstract class ?
    and,what is the difference between abstract and class ?

    blow me ... ...

  7. #7
    Registered User hk_mp5kpdw's Avatar
    Join Date
    Jan 2002
    Location
    Northern Virginia/Washington DC Metropolitan Area
    Posts
    3,798
    Quote Originally Posted by Hermitsky
    abstract class? what is abstract class ?
    and,what is the difference between abstract and class ?
    Search the web, here's one result.
    "Owners of dogs will have noticed that, if you provide them with food and water and shelter and affection, they will think you are god. Whereas owners of cats are compelled to realize that, if you provide them with food and water and shelter and affection, they draw the conclusion that they are gods."
    -Christopher Hitchens

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. problem with classes and pointers
    By Akkernight in forum C++ Programming
    Replies: 18
    Last Post: 02-21-2009, 05:21 AM
  2. Class with pointers to other classes as member data.
    By Sclorch in forum C++ Programming
    Replies: 2
    Last Post: 02-09-2009, 04:59 AM
  3. Pointers, Classes, and Errors o my!
    By Scottc1988 in forum C++ Programming
    Replies: 12
    Last Post: 03-13-2003, 09:14 PM
  4. Pointers to classes
    By Unregistered in forum C++ Programming
    Replies: 11
    Last Post: 06-02-2002, 09:25 PM
  5. question time (classes and pointers)
    By swarm in forum C++ Programming
    Replies: 1
    Last Post: 02-20-2002, 10:33 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21