Results 1 to 3 of 3

Thread: how to swap two different class objects using void pointers in c++

  1. #1
    Join Date
    Feb 2015
    Posts
    22
    Qt products
    Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android

    Default how to swap two different class objects using void pointers in c++

    hai

    i have class A and Class B along with two objects

    A a1;
    B b1;

    (void *)

    so i want to swap two objects using void pointer

    Can anyone help me...do the needful asap

  2. #2
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: how to swap two different class objects using void pointers in c++

    What do you mean with swap? swap what?

    What is the situation you want to arrive at?

    Cheers,
    _

  3. #3
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,324
    Thanks
    316
    Thanked 871 Times in 858 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: how to swap two different class objects using void pointers in c++

    You mean you want to do something like this?

    Qt Code:
    1. A * a = new A();
    2. B * b = new B();
    3.  
    4. A * c = (A *)( void * )b;
    To copy to clipboard, switch view to plain text mode 

    You might be able to fool the compiler into accepting code like that, but what do you think will happen when you try to execute a member function of class A when the variable c actually points to an instance of class B?

Similar Threads

  1. Replies: 6
    Last Post: 9th April 2013, 16:26
  2. Signals Slots and Class Pointers
    By Atomic_Sheep in forum Newbie
    Replies: 18
    Last Post: 7th September 2012, 09:08
  3. Replies: 3
    Last Post: 6th April 2012, 16:44
  4. Problems passing an array of pointers to objects to a function
    By Valheru in forum General Programming
    Replies: 16
    Last Post: 30th June 2008, 00:11
  5. diffrence between void and virtual void
    By raphaelf in forum General Programming
    Replies: 2
    Last Post: 23rd February 2006, 13:58

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Qt is a trademark of The Qt Company.