×

Discussion Board

Results 1 to 2 of 2
  1. #1
    Registered User
    Join Date
    Oct 2007
    Posts
    14

    Post how to return different class instance, if at one time one object is present

    I have a class c which has instance of classes fs nad s.but will have one instance of class(either s or fs) at one time. The inline function foo returns object of s, in some cases need to return instance of fs using same function. Can any one help me how can i achive this. External class uses this finction to get information. Here only return type need to be different, depend on which class object is created at that time.

    class fs
    {}

    class s
    {}

    class c
    {
    public:
    inline s foo()
    {
    return s;
    }
    }

    Thanks and Regards,
    Ravikanth

  2. #2
    Nokia Developer Moderator
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    28,752

    Re: how to return different class instance, if at one time one object is present

    The concrete return type has to be available in compilation time, so strictly said you can not do that. A thing you could do is returning a union of the two classes.
    You can also make s and fs to be relatives, and return pointers/refernces (const or non-const, depending on the use-case) to the higher level one - and provide a way to check what the actual object is.

    You can find more about C++ in a C++ book.

Similar Threads

  1. How to get the Major Device Class at Discovery Time
    By HansPrové in forum Bluetooth Technology
    Replies: 2
    Last Post: 2008-04-16, 13:32
  2. Page builder
    By giogiogio in forum Symbian
    Replies: 2
    Last Post: 2007-08-26, 18:08
  3. Replies: 2
    Last Post: 2007-03-14, 17:15
  4. Replies: 0
    Last Post: 2005-12-09, 14:12
  5. How to make singleton
    By rownak_hasan in forum Symbian Tools & SDKs
    Replies: 2
    Last Post: 2003-02-06, 23:15

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
×