Referencing Classes?

This is a discussion on Referencing Classes? within the C++ Programming forums, part of the General Programming Boards category; Is it possible to reference a class? I was thinking something like this? Code: class classOne { ... }; class ...

  1. #1
    carry on JaWiB's Avatar
    Join Date
    Feb 2003
    Location
    Seattle, WA
    Posts
    1,972

    Referencing Classes?

    Is it possible to reference a class?
    I was thinking something like this?
    Code:
    class classOne
    {
    ...
    };
    
    class &classOneRef = classOne;
    
    ...
    It's not really important. I just wanted to know...
    "Think not but that I know these things; or think
    I know them not: not therefore am I short
    Of knowing what I ought."
    -John Milton, Paradise Regained (1671)

    "Work hard and it might happen."
    -XSquared

  2. #2
    Rebooted Inquirer's Avatar
    Join Date
    Apr 2002
    Posts
    281
    Yes, i do believe you can. How else would you be able to pass a class reference to a function that takes a void*? I may, however, be wrong. It wouldn't be the first time.

    ~Inquirer
    Compilers:
    GCC on Red Hat 8.1 (Primary)
    GCC on Mac OS X 10.2.4 (Secondary)

    Others:
    MinGW on XP

  3. #3
    Registered User
    Join Date
    Apr 2003
    Posts
    2,662
    That sure doesn't look right to me. A reference to the keyword class?

    "How else would you be able to pass a class reference..."

    Like this?

    class classOne
    {
    ...
    };

    classOne a;

    classOne& b = a;
    Last edited by 7stud; 04-29-2003 at 10:09 PM.

  4. #4
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,892
    You could do a typedef:
    Code:
    class className {
    // ...
    };
    
    typedef className otherClassName;
    typedef className &classNameRef;
    A variable of otherClassName is then the same as one of className. A variable of classNameRef is a reference to an object of className.
    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

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Can you Initialize all classes once with New?
    By peacerosetx in forum C++ Programming
    Replies: 12
    Last Post: 07-02-2008, 10:47 AM
  2. Multiple Inheritance - Size of Classes?
    By Zeusbwr in forum C++ Programming
    Replies: 10
    Last Post: 11-26-2004, 08:04 AM
  3. im extreamly new help
    By rigo305 in forum C++ Programming
    Replies: 27
    Last Post: 04-23-2004, 11:22 PM
  4. Exporting VC++ classes for use with VB
    By Helix in forum Windows Programming
    Replies: 2
    Last Post: 12-29-2003, 04:38 PM
  5. Prime Number Generator... Help !?!!
    By Halo in forum C++ Programming
    Replies: 9
    Last Post: 10-20-2003, 07:26 PM

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