none
Public virtual function not inherited by derived class

    问题

  • I'm working with a convoluted set of very bloated classes in a non-managed DLL (i.e., not .NET), and have encountered a strange problem. I'll try to summarize.

    First, the class hierarchy looks like this (names abbreviated to protect the innocent):

    class RBAC;
    class RIP : public RBAC;
    class RMP : public RIP;
    class RFXP : public RIP; 
    class RCDP : public RFXP;
    class RFP : public RFXP; 
    class RCFP : public RFP;
    class REIRP : public RCFP;
    class REPRDCP : public REIRP;
    class RERAP : public REIRP;

    Within class RIP, we declare a function as follows (and also define it):

    // RPS, RME, and RD are classes outside this hierarchy
    virtual RPS * PS(const RME * me, const RD& d) const;

    This function, PS, is redefined in class RMP. It is inherited by class RFXP--at least, so the Object Browser in VS2010 tells me, and I see no reason to doubt it. But the Object Browswer doesn't list it in class RFP.

    Meanwhile, there are absolutely no occurrences of the name of the function anywhere in the header or source files for classes RFXP or RFP.

    So the question is: Why isn't class RFP inheriting this function from RFXP?

    It is true that I am relying on the Object Browser on this point. Is it reliable? Should I stick a random call to PS somewhere inside the code of class RFP, just to see if the linker finds it?

    Any hints would be greatly appreciated, as I'm stumped at the moment over this one.


    2012年3月13日 20:30

答案

  • Well, I think the best way is to stick a random call to this function somewhere and see if it works. If it doesn't try to compile it, hopefully you will get an error message that helps if that function isn't found in the derived class.

    Unfortunately without any kind of code what we can suggest is limited.


    This is a signature

    Any samples given are not meant to have error checking or show best practices. They are meant to just illustrate a point. I may also give inefficient code or introduce some problems to discourage copy/paste coding. This is because the major point of my posts is to aid in the learning process.

    Do you want Visual Studio 11 Express to be freely installable on Windows 7 and able to write regular C++ applications? Please vote for this.

    2012年3月13日 20:45

全部回复

  • Well, I think the best way is to stick a random call to this function somewhere and see if it works. If it doesn't try to compile it, hopefully you will get an error message that helps if that function isn't found in the derived class.

    Unfortunately without any kind of code what we can suggest is limited.


    This is a signature

    Any samples given are not meant to have error checking or show best practices. They are meant to just illustrate a point. I may also give inefficient code or introduce some problems to discourage copy/paste coding. This is because the major point of my posts is to aid in the learning process.

    Do you want Visual Studio 11 Express to be freely installable on Windows 7 and able to write regular C++ applications? Please vote for this.

    2012年3月13日 20:45
  • Well, I think the best way is to stick a random call to this function somewhere and see if it works. If it doesn't try to compile it, hopefully you will get an error message that helps if that function isn't found in the derived class.

    I agree with Crescens2k. In fact, I would have thought the test would take less time than posting the question here.
    2012年3月13日 20:58
  • All right, I've launched another build, which will take 1-2 hours. When I posted my question, I was running another build to test a different approach to the problem. Unfortunately, this DLL makes it difficult to change anything without changing one of the header files, and the header files are included everywhere, hence the inordinately long builds.

    Are there any known issues with the Object Browser failing to list functions that are in fact being inherited? Where might I find lists of known issues along those lines? I'm new to the MS tools, and to researching possible misbehavior on their part.


    Norman Birkett

    2012年3月13日 21:16
  • From what I remember, the default settings for Object Browser doesn't list inherited members. You need to set something in the Object Browser settings for this to be listed.

    If you go to the Object Browser window, look for the icon of the list with a tick at the top left corner and a little downward pointing triangle to its left. If you click on the little triangle and in the menu that appears make sure Inherited Members has a tick next to it, if not select it. It will then show the members that are inherited from base classes.


    This is a signature

    Any samples given are not meant to have error checking or show best practices. They are meant to just illustrate a point. I may also give inefficient code or introduce some problems to discourage copy/paste coding. This is because the major point of my posts is to aid in the learning process.

    Do you want Visual Studio 11 Express to be freely installable on Windows 7 and able to write regular C++ applications? Please vote for this.

    2012年3月13日 21:28
  • Thanks for that suggestion, but I don't think that's the problem. I can see lots and lots of inherited members in the Object Browser. That's how I concluded, for example, that PS is being inherited by class RFXP.


    Norman Birkett

    2012年3月13日 21:36
  • I've always had the opposite problem with Object Browser. It usually shows too many members. For example:

    class a
    {
    public:
    	virtual int myfun() {return 0;}
    	virtual int myfun(char *){return 1;}
    };
    
    class b : public a
    {
    public:
    	virtual int myfun(int ma) {return ma;}
    private:
    	virtual int myfun() {return 0;}
    };
    
    class c : public b
    {
    public:
    };

    In Object Browser this shows two members that I think it shouldn't show. First it shows int myfun(char *) under both b and c even though it has been hidden by the definition of the myfun overloads in b (and the obvious lack of using to bring a::myfun into b).

    The second is that for c, int myfun() is listed and it refers back to int a::myfun() (notice again the lack of using a::myfun;). While it is true that it is accessable via

    c myc;
    c.a::myfun();

    calling the member directly would try to go through b::myfun() and give a compiler error.

    So I would say that if Object Explorer doesn't list it then it truely can't find a path to it for some reason. Otherwise from my own experience, it would show it.


    This is a signature

    Any samples given are not meant to have error checking or show best practices. They are meant to just illustrate a point. I may also give inefficient code or introduce some problems to discourage copy/paste coding. This is because the major point of my posts is to aid in the learning process.

    Do you want Visual Studio 11 Express to be freely installable on Windows 7 and able to write regular C++ applications? Please vote for this.



    2012年3月13日 22:17
  • Well, folks, the results are in:

    The linker was able to resolve the following call, appearing within code in class RFP:

    anRPSptr = RFP::PS(someMEptr, someD);

    So the function PS really is being inherited by RFP, at least as far as the linker is concerned.

    Interestingly, even with that call in the RFP code, the Object Browser still refuses to list PS as an available member function of RFP, even though it lists lots of other members that are inherited in exactly the same way (both functions and variables).

    It's also interesting that if I type "this->" within the RFP code, the little menu that appears listing things one can type next DOES include the function PS. So that feature has one view (shared by the linker) while the Object Browser has another view.

    Creskens2k -- I have also noticed the Object Browser ignoring the Blocking Rule in the way you describe. And I'm with you that this is the first time I've noticed the Object Browser erring in the other direction. Thanks for your efforts to help.

    I will post another reply if I ever figure out how to get PS to appear in the Object Browser. There's got to be SOME explanation, after all.


    Norman Birkett

    2012年3月14日 13:15