Can you assign an object of a derived class to an object of its base class?

This is a discussion on Can you assign an object of a derived class to an object of its base class? within the C++ Programming forums, part of the General Programming Boards category; without any class being modified to accept those parameters?...

  1. #1
    Unregistered
    Guest

    Can you assign an object of a derived class to an object of its base class?

    without any class being modified to accept those parameters?

  2. #2
    Budding Synth Programmer samGwilliam's Avatar
    Join Date
    Feb 2002
    Location
    Trefforest
    Posts
    368
    I believe you can. Try it. I know for sure that you can pass a derived class to a function where the parameter expects a base class, so why not?
    MSVC++ 6.0

  3. #3
    GeekSeb
    Guest
    I DOnt Think So.

    Im assuming you are using protected variables. If it is a common varaible to both the base class and the derived class then yeah it should probably work. Otherwise, trying to assign a derived class variable to a non-existant variable in a base class would be invalid.

  4. #4
    Budding Synth Programmer samGwilliam's Avatar
    Join Date
    Feb 2002
    Location
    Trefforest
    Posts
    368
    That's what I meant. I've never tried it, but it seems logical that you could do it. C++ still manages to surprise me with its flexibility sometimes.
    MSVC++ 6.0

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. derived class can not access base class protected member?
    By George2 in forum C++ Programming
    Replies: 2
    Last Post: 10-21-2007, 06:32 PM
  2. derived class
    By BKurosawa in forum C++ Programming
    Replies: 9
    Last Post: 08-09-2007, 02:18 PM
  3. Base class initialization
    By VirtualAce in forum C++ Programming
    Replies: 4
    Last Post: 01-11-2004, 03:52 AM
  4. Replies: 1
    Last Post: 11-27-2001, 12:07 PM
  5. Exporting Object Hierarchies from a DLL
    By andy668 in forum C++ Programming
    Replies: 0
    Last Post: 10-20-2001, 01:26 PM

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