Private inheritance and dynamic cast issue

Hello. I am hitting a problem combining private inheritance and dynamic casting, using Sun Studio 12 (Sun C++ 5.9 SunOS_sparc Patch 124863-01 2007/07/25):
I have three related classes. Let's call them:
Handle: The basic Handle class.
DspHandle. Handle implementation, able to add itself to a Receiver.
IODriver. Implemented in terms of DspHandle, It is the actually instantiated object.
Consider the following code. Sorry, but I've tried my best trying to minimize it:
#include <iostream>
using namespace std;
class Handle {
public:
virtual ~Handle() {};
class Receiver {
public:
void add(Handle &a);
class DspHandle : public Handle {
public:
virtual ~DspHandle() {};
void run(Receiver &recv);
class IODriver : private DspHandle {
public:
void start(Receiver &recv) {
DspHandle::run(recv);
void DspHandle::run(Receiver &recv) {
cout << "Calling Receiver::add(" << typeid(this).name() << ")" << endl;
recv.add(*this);
void Receiver::add(Handle &a) {
cout << "Called Receiver::add(" << typeid(&a).name() << ")" << endl;
DspHandle d = dynamic_cast<DspHandle>(&a);
cout << "a= " << &a << ", d=" << d << endl;
int main(int argc, char *argv[]) {
Receiver recv;
IODriver c;
c.start(recv);
Compiling and running this code with Sun Studio 12:
CC -o test test.cc
./test
Calling Receiver::add(DspHandle*)
Called Receiver::add(Handle*)
a= ffbffd54, d=0
The dynamic cast in Receiver::add, trying to downcast Handle to DspHandle, fails.
This same code works, for example with GNU g++ 4.1.3:
Calling Receiver::add(P9DspHandle)
Called Receiver::add(P6Handle)
a= 0xbfe9c898, d=0xbfe9c898
What is the reason of the dynamic_cast being rejected. Since the pointer is actually a DspHandle* , even when it is part of a private class, shouldn't it be downcastable to DspHandle? I think that perhaps the pointer should be rejected by Receiver::add(Handle &a) as it could be seen as a IODriver, that can't be converted to its private base. But since it's accepted, shouldn't the dynamic_cast work?
Changing the inheritance of IODriver to public instead of private avoids the error, but it's not an option in my design.
So, questions: Why is it failing? Any workarround?
Best wishes.
Manuel.

Thanks for your fast answer.
But could you please provide a deeper answer? I would like to know where do you think the problem is. Shouldn't the reference be accepted by Receiver:add, since it can only be seen as a Handle using its private base, or should the dynamic_cast work?
Aren't we actually trying to cast to a private base? However, casting to private bases directly uses to be rejected in compile time. Should the *this pointer passed from the DspHandle class to Receiver be considered a pure DspHandle or a IODriver?
Thanks a lot.

Similar Messages

  • Slow program response, crashes when creating titles and dynamic link issues

    Dear reader,
    I am now trialling Adobe CC OSX with Premiere Pro and After Effects before deciding to subscribe but I am experiencing a lot of issues while working.
    I am now working on an animation, but editing raw mxf files also gives crashes and slow responses/ program refreshes.
    1) Slow mouse response
    2) Slow program refresh while key framing visuals
    3) Rendering in PP is extremely slow when AE is open in the background, when closing AE and re-initiate the render in PP it renders super fast
    4) Crashes. When I overlay titles in my time line PP regularly crashes
    5) Dynamic Link issues when working combined in AE and PP where file connections in the time line get lost when the AE project has too many sequences
    I am curious to find out if other people are also experiencing these issues.
    I am indecisive in getting the paid yearly plan or move to FCPX instead? Or should I get a new MacPro and is this model too old?
    It worked fine 2 months ago, however I was still working on FCP7. After updating it is really bad working with it...
    My system consist of:
    MacPro mid-2010
    OSX 10.9.5 (13F34) (new installation)
    2x2,66Ghz 6-core Intel Xeon
    24GB DDR3 ECC
    Nvidia Quadro K5000, 4GB
    2x PCIe SSD 1TB
    2x HDD 3TB
    2x HDD 2TB
    Feedback is much appreciated! Best regards, Alexander

    this does work for basic colour correction but not when trying to grade an entire suqence to achieve a specific style, applying a vingette or certain effects have to be done in after effects.
    I want to try and get my whole sequence into after effects but preserve the edits and effects added in permier pro, is there any way to do this?
    rich

  • Inheritance and access control - "private protected"

    I'm reopening an old topic, seems to have been last discussed here 2-3 years ago.
    It concerns the concept of restricting access to class members to itself, and its subclasses. This is what "protected" does in C++ and "private protected" did in early versions of the Java language. This feature was removed from Java with a motivation along the lines of not being "simple", and "linear" (in line with the other access modes, each being a true subset of the next). Unfortunately, the article which explained Sun's position on this keyword combination seems to have been removed from the site, so I haven't been able to read its original text.
    But regardless of simplicity of implementation or explaining Java's access modifiers to newbies, I believe it is a fundamental part of OO programming for such an access mode to exist. The arguments for having the standard "private" mode in fact also apply for having a C++-style "protected" mode. (Arguing that classes within a package are related and it therefore doesn't hurt to also give them access to Java's "protected" members, is equally arguing that "private" is unneccessary, which noone of course believes.)
    The whole concept of inheritance and polymorphism and encapsulation builds on the access modes private, protected, and public (in the C++ senses). In Java the "package" concept was added - a nice feature! But I see no justification for it to negate the proper encapsulation of a class and its specializations.

    What effect upon inheritance other than hiding members
    from subclasses is there?
    None. And I cant think of another declaration that prevents members from being inherited but private.
    Of course the onus comes on the programmer with Java's
    definition of "protected" - but
    1) there is rarely a single programmer working within
    a package
    The point was the package is a unit which does not hide from itself. Just like all methods within a class can see each other, all classes within a package can, and all packages within a program can.
    2) it muddies the encapsulation in the design - when
    you see a "protected" method someone else, or yourself
    some time ago - wrote, how do you know if the design
    intention is to have it accessed solely by the class
    and its subclasses, or if it is indeed intended to be
    shared with the whole package? The only way to do
    this today is to always explicitly specify this in the
    comments, which may be lacking, inconsistent, and
    abused (since it isn't enforced).Encapsulation would be implementation hiding. Not method hiding. The only thing you should probably allow out of your package is an interface and a factory anyway.
    I understand where you are coming from, but I really have not had occasion to take issue with it. I can't think of a real codeing situation where this is required. OTOH, I can't think of a coding situation where I need to access a protected method from another class either.

  • Private attributes and Inheritance.

    I have a question regarding 'private attributes and inheritance'.
    If I have a class that will be extended by other classes,(basically
    this will act as a BASE class ),then why do I need to define
    any attribute private to this base class.?
    If I define an attribute as private in the base class,then the subclass cannot access
    this attribute.Right?
    1) Why define a private attribute in the base class ?
    2) When can a situation arise whereby the base class attribute is defined
    as 'private' and the base class is also extensible?

    If I define an attribute as private in the base
    class,then the subclass cannot access
    this attribute.Right?Right. A simple example would tell you this.
    >
    1) Why define a private attribute in the base class?Because information hiding and encapsulation are always good things, even between super and sub classes.
    >
    2) When can a situation arise whereby the base class attribute is defined
    as 'private' and the base class is also extensible?This question makes no sense whatsoever. A base class is extensible, unless it is marked as final, whether or not it's got private data members.
    Objects usually have private state and public interfaces. The idea is that clients of a class, even subclasses, should only access the private state thorugh the public interface. So if you've designed your classes properly you shouldn't need to access that private state.
    If you do, you can always provide get/set methods.
    OR declare the data members as protected. That way they're package visible and available to subclasses.
    But private members do not make a class inextensible.
    %

  • FileChooser.getSelectedFiles() override and casting issues

    I want to extend the FileChooser class and override its getSelectedFiles method so that it not only returns all selected files, but returns files inside directorys recursively. my code looks like...
    public File[] getSelectedFiles()
    File[] files = super.getSelectedFiles();
    List retVals = new ArrayList();
    for(int i=0; i<files.length; i++)
    if(files.isDirectory())
    retVals.addAll( a recursive function that grabs files from directories and subdirectories );
    else
    retVals.add(files[i]);
    return (File[])retVals.toArray();
    my problem is the return line generates a ClassCastException, which makes sense because File[] is not a descendent of Object[], even though File is a descendent of Object. So what's the work around without alot of hassle? My approach so far seems the best in terms of OO... I'm extending a class and overriding the method I want, and even if I generated a whole new method, there doesn't seem to be a good way to use a List's add-to flexibility and then cast the final result back to an array to return. My hunch is the ultimate way to do this without writing an elaborate data structure is to declare a File[REALLY_BIG_SIZE] to be partially filled and then returned.
    also, in my recursive function i do...
    dir.listFiles(this.getFileFilter())
    and it complains that listFiles() cannot take an operand FileFilter, but there IS a listFiles(FileFilter) function, it's like the editor knows about it, but the debugger doesn't (I'm using Eclipse). any ideas here?

    I want to extend the FileChooser class and override
    its getSelectedFiles method so that it not only
    returns all selected files, but returns files inside
    directorys recursively. my code looks like...
    public File[] getSelectedFiles()
    File[] files = super.getSelectedFiles();
    List retVals = new ArrayList();
    for(int i=0; i<files.length; i++)
    if(files.isDirectory())
    retVals.addAll( a recursive function
    ursive function that grabs files from directories and
    subdirectories );
    else
    retVals.add(files[i]);
    return (File[])retVals.toArray();
    my problem is the return line generates a
    ClassCastException, which makes sense because File[]
    is not a descendent of Object[], even though File is
    a descendent of Object. So what's the work around
    without alot of hassle? My approach so far seems the
    best in terms of OO... I'm extending a class and
    overriding the method I want, and even if I generated
    a whole new method, there doesn't seem to be a good
    way to use a List's add-to flexibility and then cast
    the final result back to an array to return. My
    hunch is the ultimate way to do this without writing
    an elaborate data structure is to declare a
    File[REALLY_BIG_SIZE] to be partially filled and then
    returned.
    also, in my recursive function i do...
    dir.listFiles(this.getFileFilter())
    and it complains that listFiles() cannot take an
    operand FileFilter, but there IS a
    listFiles(FileFilter) function, it's like the editor
    knows about it, but the debugger doesn't (I'm using
    Eclipse). any ideas here?
    change the last line to :
    return (File[]) retVals.toArray(new File[] {});

  • Narrow Cast and Widening cast in OOPs

    hi friends,
    Can u please clear with the above two concepts ..... i have many doubts on this ...
    first of all Y we need the concept of Narrow cast and widenning cast ?
    Expecting your answers ...
    Thanks in advance
    Cheers
    Kripa Rangachari .....

    hi Kripa,
    “Narrowing” cast means that the assignment changes from a more specialized view (with visibility to more components) to a more generalized view (with visibility to fewer components).
    “Narrowing cast” is also referred to as “up cast” . “Up cast” means that the static type of the target variable can only change to higher nodes from the static type of the source variable in the inheritance tree, but not vice versa.
    <b>Reference variable of a class assigned to reference variable of class : object</b>
    class c1 definition.
    endclass.
    class c1 implementation.
    endclass.
    class c2 definition inheriting from c1.
    endclass.
    class c2 implementation.
    endclass.
    start-of-selection.
    data : oref1 type ref to c1,
            oref2 tyep ref to c2.
    oref1 = oref2.
    <b>Widening Cast</b>
    DATA:     o_ref1 TYPE REF TO object,                o_ref2 TYPE REF TO class.
    o_ref2 ?= o_ref1.
    CATH SYSTEM-EXCEPTIONS move_cast_error = 4.
         o_ref2 ?= o_ref1.
    ENDCATCH.
    In some cases, you may wish to make an assignment in which the static type of the target variable is less general than the static type of the source variable. This is known as a widening cast.
    The result of the assignment must still adhere to the rule that the static type of the target variable must be the same or more general than the dynamic type of the source variable.
    However, this can only be checked during runtime. To avoid the check on static type, use the special casting operator “?=“ and catch the potential runtime error move_cast_error
    Regards,
    Richa

  • Pivot and dynamic SQL

    Hi Team,
    I need to write a SQL to cater the requirements. Below is my requirements:
    pagename fieldname fieldvalue account_number consumerID
    AFAccountUpdate ArrangementsBroken dfsdff 1234 1234
    AFAccountUpdate ArrangementsBroken1 dfsdff 1234 1234
    AFAccountUpdate ArrangementsBroken2 dfsdff 1234 1234
    AFAccountUpdate ArrangementsBroken2 dfsdff 12345 12345
    AFAccountUpdate ArrangementsBroken1 addf 12345 12345
    Create table test_pivot_dynamic
    pagename varchar(200),
    fieldname Varchar(200),
    fieldvalue varchar(500),
    N9_Router_Account_Number bigint,
    TC_Debt_Item_Reference bigint
    --Input
    insert into test_pivot_dynamic Values('AFAccountUpdate','ArrangementsBroken','addf',1234,1234)
    insert into test_pivot_dynamic Values('AFAccountUpdate','ArrangementsBroken1','dfsdff',1234,1234)
    insert into test_pivot_dynamic Values('AFAccountUpdate','ArrangementsBroken2','fder',1234,1234)
    insert into test_pivot_dynamic Values('AFAccountUpdate','ArrangementsBroken2','dfdfs',12345,12345)
    insert into test_pivot_dynamic Values('AFAccountUpdate','ArrangementsBroken1','dfdwe',12345,12345)
    insert into test_pivot_dynamic Values('AFAccountUpdate1','Arrangements','addf',1234,1234)
    insert into test_pivot_dynamic Values('AFAccountUpdate1','Test1','dfsdff',1234,1234)
    --Expected output:
    Select 1234,1234,'AFAccountUpdate','ArrangementsBroken','addf','ArrangementsBroken1','dfsdff','ArrangementsBroken2','fder','ArrangementsBroken2','fder'
    Select 12345,12345,'AFAccountUpdate','ArrangementsBroken','addf','ArrangementsBroken1','dfdwe','ArrangementsBroken2','dfdfs'
    Select 1234,1234,'AFAccountUpdate1','Arrangements','addf','Test1','dfsdff'
    so basically we have to pivot and dynamic sql and insert the expected output to a common table which will have all the required fields
    Thanks,Ram.
    Please don't forget to Marked as Answer if my post solved your problem and use Vote As Helpful if a post was useful. It will helpful to other users.

    This should give you what you're looking for
    SELECT N9_Router_Account_Number,TC_Debt_Item_Reference,PageName,
    MAX(CASE WHEN SEQ = 1 THEN fieldname END) AS fieldname1,
    MAX(CASE WHEN SEQ = 1 THEN fieldvalue END) AS fieldvalue1,
    MAX(CASE WHEN SEQ = 2 THEN fieldname END) AS fieldname2,
    MAX(CASE WHEN SEQ = 2 THEN fieldvalue END) AS fieldvalue2,
    MAX(CASE WHEN SEQ = 3 THEN fieldname END) AS fieldname3,
    MAX(CASE WHEN SEQ = 3 THEN fieldvalue END) AS fieldvalue3,
    MAX(CASE WHEN SEQ = 4 THEN fieldname END) AS fieldname4,
    MAX(CASE WHEN SEQ = 4 THEN fieldvalue END) AS fieldvalue4
    FROM
    SELECT *,ROW_NUMBER() OVER (PARTITION BY N9_Router_Account_Number,TC_Debt_Item_Reference,PageName ORDER BY PageName) AS SEQ,*
    FROM test_pivot_dynamic
    )t
    GROUP BY N9_Router_Account_Number,TC_Debt_Item_Reference,PageName
    To make it dynamic see
     http://www.beyondrelational.com/modules/2/blogs/70/posts/10791/dynamic-crosstab-with-multiple-pivot-columns.aspx
    Please Mark This As Answer if it helps to solve the issue Visakh ---------------------------- http://visakhm.blogspot.com/ https://www.facebook.com/VmBlogs

  • Difference between public void, private void and public string

    Hi everyone,
    My 1st question is how do you know when to use public void, private void and public string? I am mightily cofuse with this.
    2ndly, Can anybody explain to me on following code snippet:
    Traceback B0;//the starting point  of Traceback
    // Traceback objects
    abstract class Traceback {
      int i, j;                     // absolute coordinates
    // Traceback2 objects for simple gap costs
    class Traceback2 extends Traceback {
      public Traceback2(int i, int j)
      { this.i = i; this.j = j; }
    }And using the code above is the following allowed:
    B[0] = new Traceback2(i-1, 0);
    Any replies much appreciated. Thank you.

    1)
    public and private are access modifiers,
    void and String return type declarations.
    2)
    It's called "inheritance", and "bad design" as well.
    You should read the tutorials, you know?

  • The Ultimate Guide to Resolving Profile and Device Manager Issues

    The following article also applies to issues after re-setting the severs' hostname. It also applies to situations where re-setting the Code Signing Certifictateas described by Apple has not resolved the issue.
    Hello,
    I have been plagued with Profile Manager and Device Manager issues since day one.
    I would like to share my experience and to suggest a way how to resolve issues such as device cannot be enrolled or Code Signing Certificate not accepted.
    I shall try to be as brief as possible, just giving an overview of the steps that resolved my issues. The individual steps have been described elsewhere in this forum. For users who have purchased commercial SSL certs the following may not apply.
    In my view many of these issues are caused by missing or faulty certificates. So let us first touch on the very complex matter of certificates.
    Certificates come in many flavours such as CA (Certificate Authority), Code Signing Certificate, S/MIME and Server Identification.
    (Mountain?) Lion Server creates a so-called Intermediate CA certificate (IntermediateCA_hostname_1") and Server Identification Certificate ("hostname") when it installs first. This is critical for the  operation of many server functionalities, including Open Direcory. These certs together with the private/public keys can be found in your Keychain. Profile  and Device Manager may need a Code Signing Certificate.
    The most straightforward way to resolve the Profile Manaher issues is in my view to reset the server created certicates.
    The bad news is that this procedure involves quite a few steps and at least 2 hours of your precious time because it means creating a fresh Direcory Master.
    I hope that I have not forgotten to mention an important step. Readers' comments and addenda are welcome.
    I shall outline a sensible strategy:
    1. Clone your dysfunctional server to an external harddrive (SuperDuper does a reliable job)
    2. Start the server fom the clone and shut down ALL services.
    3. It may be sensible to set up a root user access.
    4. Back-up all user data such as addess book, calendar and other data that you *may* need to set up your server.
    5. Open Workgroup Manager and export all user and workgroup accounts to the drive that you using to re-build your server (it may cause problems if you back-up to an external drive).
    6. Just in case you may also want to back-up the Profile Manager database and erase user profiles:
    In Terminal (this applies to Lion Server - paths may be diferent in Mountain Lion !)
    Backup: sudo pg_dump -U _postgres -c device_management > $HOME/device_management.sql
    Erase database:
    sudo /usr/share/devicemgr/backend/wipeDB.sh
    7. Note your Directory (diradmin) password for later if you want to re-use it.
    8. Open Open Server Admin and demote OD Master to Standalone Directory.
    9. In Terminal delete the old Certificate Authority
    sudo rm -R /var/root/Library/Application\ Support/Certificate\ Authority/
    This step is crucial because else re-building you OD Master will fail.
    9. Go back to Server Admin and promote the Standalone Directory to OD Master. You may want to use the same hostname.
    10. When the OD Master is ready click on Overview and check that the LDAP and Keberos Realm reflect your server's hostname.
    11. Go back to Workgroup Manager and re-import users and groups.
    NOTE: passwords are not being exported. I do not know how to salvage user passwords. (Maybe passwords can be recovered by re-mporting an OD archive - comments welcome! ).
    12. Go to Server App and reset passwords and (not to forget) user homefolder locations, in particular if you want to login from a network account!
    If the home directory has not been defined you cannot login from a network account.
    13. You may now want to restore Profile Manager user profiles in Terminal. Issue the following commands:
    sudo serveradmin stop devicemgr
    sudo serveradmin start postgres
    sudo psql -U _postgres -d device_management -f $HOME/device_management.sql
    sudo serveradmin start devicemgr
    14. You can now switch back on your services, including Profile Manager.
    In Profile Manager you may have to configure Device Management. This creates a correct Code Signng Certicate.
    15. Check the certificate settings in Server App -> Hadware -> Settings-> SSL Certificates.
    16. Check that Apple Push Notifications are set.(you easily check if they are working later)
    17. You may want to re-boot OS Server from the clone now.
    18. After re-boot open Server App and check that your server is running well.
    19. Delete all profiles in System Preferences -> Profiles.
    19. Login to Profile Manager. You should have all users and profiles back. In my experience devices have to be re-enrolled before profiles can be pushed and/or devices be enrolled. You may just as well delete the displayed devices now.
    20. Grab one of your (portable) Macs that you want to enrol and go to (yourhostname)/mydevices and install the server's trust profile. The profile's name  should read "Trust Profile for...) and underneath in green font "Verified".
    21. Re-enrol that device. At this stage keep your finger's crossed and take a deep breath.
    22. If the device has been successfully enrolled you may at last want to test if pushing profiles really works. Login to Profile Manager as admin, select the newly enrolled device. Check that Automatic Push is enabled (-> Profile -> General). Create a harmless management profile such as defining the dock's position on the target machine. (Do not forget to click SAVE at the end - this is easily missed here). If all is well Profile Manager will display an active task (sending) and the dock's position on the target will have changed in a few seconds if you are on a LAN (Note: If sending seems to take forever: check on the server machine and/or on your router that the proper ports are open and that incoming data is not intercepted by Little Snitch or similar software).
    Note: if you intend to enrol an Apple iPhone you may first need to install the proper Apple Configuration software.
    Now enjoy Profile and Device Manager !
    Regards,
    Twistan

    HI
    1. In Action profiles, logon to system and recheck correcion are available in action definition as well in condition configuration and the schedule condition is also maintained. but the display is not coming(i.e in the worklist this action is not getting displayed).
    You can check the schedule condition for the action and match the status values...or try recreating the action with schedule condition again....for customer specific ....copy the standard aciton with ur zname and make a schedule condition and check the same.
    2, In suppport team of incident when i give individual processor it throwing a warning that u r not the processor. but when i give org unit it is working perfectly. Could anyone guide on this.
    You need to have the empolyee role for BP ..goto BP and got here dropdown for ur bp and choose role Employee and then enter ur userid
    also make sure that u have the message processing role
    Hope it clarifies ur doubt and resolve ur prob
    Regards
    Prakhar

  • Dynamic cast at runtime (Here we go again! )

    Hy folks,
    today I read so many entries about dynamic casting. But no one maps to my problem. For a lot of them individual alternatives were found. And so I hope...
    Ok, what's my problem?
    here simplified:
    I have a HashMap with couples of SwingComponents and StringArray[3].
    The SwingComponents are stored as Objects (they are all JComponents).
    The StringArray comprised "the exact ClassName" (like "JButton" or "JPanel"),
    "the method, who would be called" (like "addItemListener")
    and "the ListenerName" (like "MouseMotionListener" or "ActionListener")
    At compiletime I don't know, what JCommponent gets which Listener.
    So a JPanel could add an ItemListener, another JPanel could add
    a MouseListener and an ActionListener.
    I get the description of the GUI not until runtime.
    The 'instanceof'-resolution is not acceptable, because there are above 50 listener. If I write such a class, I would write weeks for it, and it will be enormous.
    Now, my question
    I get the class of the Listenertype by
    Class c=Class.forName(stringArray[2]);
    and the method I'll call
    java.lang.reflect.Method method=component.getClass().getDeclaredMethod(s[1],classArrayOfTheParameter[]); //the parameter is not important here
    And I have a class, who implements all required ListenerInterfaces: EHP
    Now I wish something like this
    method.invoke((JPanel)jcomponent,(c)EHP);
    Is there anybode, who can give me an alternative resolution
    without instanceof or switch-case ?
    Greatings egosum

    I see, your right. Thanks. This problem is been solved.
    But a second problem is, that jcomponent can be every Swing-Object.
    I get the swing-component as Object from the HashMap . And I know
    what it is exactly by a String.
    What I need here is
    method.invoke(("SwingType")swingcomponentObject,Object[] args);
    I know, that this doesn't exist. Here my next question
    Can I take an other structure than HashMap, where the return value
    is a safety type (and not an Object). Or there are some other hints
    about similar problems and there resolutions?
    I don't like to write 50 (or even more than 50) "instanceOf"-instructions or "equal"-queries. And I'm not really interested in the whole set of java swing elements existing.
    I appreciate all the help I can get.
    With regards egosum

  • Narrow cast and wide cast in ABAP OO

    Hi Xperts
    Considering the code below can the concepts of narrowing cast and widening cast be explained ? Kindly help me in getting a clear picture of the usage of it.
    CLASS C1 DEFINITION.
      PUBLIC SECTION.
        CLASS-DATA: COUNT TYPE I.
        CLASS-METHODS: DISP.
    ENDCLASS.                    "defintion  C1
    CLASS C1 IMPLEMENTATION.
      METHOD DISP.
        WRITE :/ COUNT.
      ENDMETHOD.                    "disp
    ENDCLASS.                    "c1 IMPLEMENTATION
    CLASS C2 DEFINITION INHERITING FROM C1.
      PUBLIC SECTION.
        CLASS-METHODS: GET_PROP.
    ENDCLASS.                    "c2  INHERITING C1
    CLASS C2 IMPLEMENTATION.
      METHOD GET_PROP.
        COUNT = 9.
        CALL METHOD DISP.
      ENDMETHOD.                    "get_prop
    ENDCLASS.                    "c2 IMPLEMENTATION
    START-OF-SELECTION.
      DATA: C1_REF TYPE REF TO C1,
            C2_REF TYPE REF TO C2.
    PS: Pls dont post any links as i already gone thru couple of those in SDN but couldnt get a clear info

    Hi
    I got to know abt narrow cast: referecing a super class ref to a subclass ref so that the methods in subclass can be accessed by the super class reference. Below is snippet of the code i'd checked. Hope this is correct to my understanding. If any faults pls correct me. Also if anyone can explain wideing cast in this context will be very helpful
    FOR NARROW CAST
    {size:8}
    CLASS C1 DEFINITION.
      PUBLIC SECTION.
        CLASS-DATA: COUNT TYPE I.
        CLASS-METHODS: DISP_COUNT.
    ENDCLASS.                    "defintion  C1
    CLASS C1 IMPLEMENTATION.
      METHOD DISP_COUNT.
        WRITE :/ 'Class C1', COUNT.
      ENDMETHOD.                    "disp
    ENDCLASS.                    "c1 IMPLEMENTATION
    CLASS C2 DEFINITION INHERITING FROM C1.
      PUBLIC SECTION.
        CLASS-METHODS: GET_PROP,
                       DISP.
    ENDCLASS.                    "c2  INHERITING C1
    CLASS C2 IMPLEMENTATION.
      METHOD GET_PROP.
        COUNT = 9.
        CALL METHOD DISP.
      ENDMETHOD.                    "get_prop
      METHOD DISP.
        WRITE :/ 'Class C2', COUNT.
      ENDMETHOD.                    "DISP
    ENDCLASS.                    "c2 IMPLEMENTATION
    START-OF-SELECTION.
      DATA: C1_REF TYPE REF TO C1,
            C2_REF TYPE REF TO C2.
      CREATE OBJECT: C2_REF TYPE C2.
    *  CREATE OBJECT: C1_REF TYPE C1.
      BREAK-POINT.
      C1_REF = C2_REF.
      CALL METHOD C1_REF->DISP_COUNT.
      CALL METHOD C1_REF->('GET_PROP').
    {size}
    Edited by: Prabhu  S on Mar 17, 2008 3:25 PM

  • Upcasting and narrow casting in oo-abap

    hi friends,
    please tell me clearly about the Up casting and Down casting with examples in OO-ABAP.
    thanks and regards.
    Moderator message : Search for available information, read forum rules before posting. Thread locked.
    Edited by: Vinod Kumar on Nov 9, 2011 5:32 PM

    Hi,
         Instance components exist separately in each instance (object) of the class and are referred using instance component selector using u2018u2019.
         Static components can be used without even creating an instance of the class and are referred to using static component selector     u2018 =>u2019 .
    CLASS c1 DEFINITION.
    PUBLIC SECTION.
      data : i_num type i value 5.
      class-data :   
        s_num type i value 6 .
    ENDCLASS.
    CLASS c1 IMPLEMENTATION.
    ENDCLASS.
    START-OF-SELECTION.
    DATA : oref1 TYPE REF TO c1 .
    CREATE OBJECT : oref1.
    write:/5 oref1->i_num.
    write:/5 c1=>s_num .
    write:/5 oref1->s_num.
                             Instance, self-referenced, and static methods can all be called dynamically; the class name for static methods can also be determined dynamically:
    u2022     oref->(method)
    u2022     me->(method)
    u2022     class=>(method)
    u2022     (class)=>method
    u2022     (class)=>(method)

  • Narrowing cast and widening cast

    Hi All,
           I want to know what is the use of a narrowing cast and a widening cast in ABAP objects.
    Can someone please give an example ?
    Regards,
    Ashish

    Hi,
    Check out this link, This will guide you on ABAP Objects
    http://www.sap-press.de/katalog/buecher/htmlleseproben/gp/htmlprobID-28?GalileoSession=22448306A3l7UG82GU8#level3~3
    Both narrow and wide casting are related to inheritance.
    In Narrow casting, you assign a runtime object of subclass to runtime object of superclass. By this assignment , you can access your subclass by using runtime object of your superclass. But here the important point is that, you are assigning subclass reference to super class reference, so you can only access the inherited components of subclass through super class reference.
    Suppose you have a super class lcl_vehicle. it has two subclasses lcl_car and lcl_truck.
    r_vehicle = r_car.
    In Wide casting, you assign a superclass reference to subclass reference . Before this, you do narrow casting,
    Now when you assign a superclass reference to subclass reference. You can access the inherited as well as the specific components of subclass.
    taking the same example,
    r_car ?= r_vehicle.
    '?='  wide cast operator.
    Regards
    Abhijeet

  • Dynamic casting

    hello all (happy new year!),
    i am trying to dynamically cast a class that is only known at runtime from the configuration file that is parsed during startup.
    the code is as follows:
    ArrayList classes = new ArrayList();
    ... (parsing)
    classes = JAFSaxParserInstance.getClasses();
    Iterator it = classes.iterator();
    while (it.hasNext())
      Object next = it.next();
      Class appToLoad = Class.forName(next.toString());
      Method instanceMethod = getInstanceMethod(appToLoad);
      Object frame = instanceMethod.invoke(null,null);
      Component[] components = new Component[MAX];
      components = ((UNKNOWN_CLASS) frame).getContentPane().getComponents();
    }without the ability to discover the class from which i have just called a getInstance() method, i seem unable to retrieve all the components of the JFrame subclass (i get a ClassCastException). for my purposes, all of the UNKNOWN_CLASSes will be subclasses of JFrame, but without explicitly being able to cast it (frame) exactly, i cannot extract the components.
    is there any way to dynamically cast such objects at runtime? by this i mean i cannot use switch statements b/c the classes are unknown prior to runtime.
    thanks!

    point well taken. i've probably designed my application wrong if it's this difficult, but let me try to explain what it is i'm trying to do.
    i had previously created a swing application whose central class (bootstrap initialized by a separate class with a main method) is a subclass of JFrame using the GridBagLayout manager. now, since more related gui applications are to be built, i thought it would be nice to build an application framework into which i could insert each standalone application into a JTabbedPane pane of the framework application.
    the application framework has the same structure as my previous application. a bootstrap main method class initializes the main application frame which builds a contentPane which contains a JTabbedPane. as this application framework frame is initializing, it parses an xml file which contains the data pertaining to each class and my DynamicLoader class attempts to load/initialize and add each class into a separate tab in the main application frame. that's where the problem arises since i don't know the exact class that will be loaded--only the xml file contains that information.
    i've read a few things about implementing interfaces in order to get around the inability to cast types at runtime, but am not too sure of how that might work.
    let me know if seeing some more of the code would help or if there's anything i should clarify.
    thanks!

  • Private dictionaries and Namespaces

    Private dictionaries and Namespaces
    We ran into an issue with some email templates in converting from RC2006 to RC2008.3 where Namespace values from Private service dictionaries were not populating correctly in RC2008.
    In the upgrade process from RC2006, any private dictionaries are converted to actual dictionaries. They are created in the Dictionary Group UPGD: PRIVATE DICTIONARIES and the dictionary name is based on the service name: PRIV_ServiceA.
    What I found as we were testing is that the Namespace parameters in Email templates (and, presumably, conditional statements and other places) no longer worked.
    The reason is that the Namespace Parameter for a private dictionary did not use a dictionary name, e.g. #SERVICE.DATA.Field1#. In order for the RC2008 version to work, we had to add dictionary references:  #SERVICE.DATA.PRIV_ServiceA.Field1#.

    Hey M.VAL,
    Thanks for the question. If your dictionary is not available after updating your device, you may need to redownload it:
    iOS: Dictionary isn't available after updating to the latest version of iOS
    http://support.apple.com/kb/TS5238
    Thanks,
    Matt M.

Maybe you are looking for

  • Multiple lines for field description in ALV

    Hi , Is there any way to display the field description in  multiple lines in ALV grid . Regards, Pradipta

  • Bank Account Reconciliation

    FI Experts, client do not have a clearing accoutn set-up for outgoign checks, therefore I am reconciling account manually first, before I introduce them to teh clearing accoutn. I  updated the encashment field for all outstanding checks, now I need t

  • Default frame work page

    Hi, How can i get default framework page in NWDS and change the jsp file, do anyone have the link or document for this. Thanks, Damodhrar.

  • No application data

    hello when I run query in bex and sap i have error no application data,I don't have Bi accelator index may it error depents on it ? I want to know if I define bi acceleator this problem solve? or it dosen't depends on it? plz help me

  • Show the nulls first in a query

    hi all i have a query like below select dept_code,dept_name from department select null,null from dual order by dept_codei need the sorting order should be dept_code and at the same time null should come first. now null is displaying as a last record