Re: Puzzling behaviour

  • From: "qubit" <lauraeaves@xxxxxxxxx>
  • To: <programmingblind@xxxxxxxxxxxxx>
  • Date: Tue, 10 Nov 2009 22:58:57 -0600

Has that changed since I was working on this stuff? All the compilers at that 
time did allow defining member functions.
I don't know if the committee threw it out after I left C++, but it was in the 
early compilers, from all the vendors.
--le

  ----- Original Message ----- 
  From: Tyler Littlefield 
  To: programmingblind@xxxxxxxxxxxxx 
  Sent: Tuesday, November 10, 2009 10:51 PM
  Subject: Re: Puzzling behaviour


  Hello,
  You can't put function callbacks inside a class, I believe that's your issue.
  HTH,


  On Nov 10, 2009, at 9:46 PM, qubit wrote:


    I have an idea -- I wonder if your curly braces aren't out of phase... but 
here are some thoughts:

    It would help if you supplied the class with the headers of the 2 procs so 
we can see what you are dealing with -- i.e., what are the names of the 
functions and the class?
    You copied just one line with some calls and conversions and refer vagely 
to an error message. Are you saying this line appears in some proc, and that 
the other proc is called on this line?

    Note the hint the error message gives: local function needs to be called or 
have its address taken.  Back when I was working on C++ compilation, we had 3 
types of scopes to deal with: global or namespace scope, nested scope (class 
member), and local (entity declared inside function block).
    If you have 2 functions the members of a class, they should be able to 
refer to each other in the definition, even if function a calls b before b is 
declared.  This is because the function bodies aren't processed until after the 
class.  Borland's compiler may have some idiosyncrasies, but I believe it does 
handle inline member function definitions correctly.  So the next thing to look 
at is whether the class is a locally declared class. Then it is still legal for 
it to have member functions, but they have to be defined and used within the 
function as they go out of scope otherwise.  So is the class in question 
declared as a local class?
    The next analogous question is, did you accidently move your global or 
member function from global scope into the body of a function? This can happen 
if the curly braces are out of phase.

    So check your scope nesting.

    One other thing: if you move a global function f into a class C, so C::f is 
a member function, and if you try to pass the address of that function to 
another function, you need to declare the parameter of the second function so 
that it has the right type.  For example, suppose f0 is the function with the 
parameter in question:
    int f() { return 1; }
    class C { public:
        int f0( int(*pf)() ) { return pf(); }
    };
    note the function pointer pf.
    Now move f() into class C so it is now a member:

    class C { public:
        int f() { return 1; }
        int f0( int(*pf)() ) { return pf(); }
    };
    The declaration of f0 is bad. You will get loude complaints, because the 
function call pf() is not a call to a member function.  Try declaring the 
following:
    class C { public:
        int f() { return 1; }
        int f0( int(C::*pf)() ) { return this->pf(); }
    };

    Note the definition of f0 has to be modified to use the right type.

    I hope thise musings are of use. I didn't expect them to get so long.
    Happy hacking.
    --le


      ----- Original Message -----
      From: Ian D. Nichols
      To: programmingblind@xxxxxxxxxxxxx
      Sent: Tuesday, November 10, 2009 10:12 PM
      Subject: Puzzling behaviour


      Hi Listers,

      I have a puzzling situation that I cannot figure out.  This is C++, using 
a Borland command-line compiler, Windows XP SP3, and JAWS 9.

      The following line compiles just fine, unless it is one of the methods in 
a class.  Dlg1Proc is also a method of the class.

      int Result = DialogBoxParam (hInstance, "Dialog1", hWnd, 
(DLGPROC)Dlg1Proc, 0);

      It does not wrap in the source file.

      If the 2 methods are in a class, the error message says that the local 
method must be called or its address taken.

      It would be much more convenient for me if it would work in the class.  
Does anyone have any idea why it won't, and what my options are?

      TIA.

      Ian

      Ian D. Nichols,
      Toronto, Canada


Other related posts: