Cannot call member function without object = C++

前端 未结 5 1416
梦谈多话
梦谈多话 2021-02-13 07:17

I am brushing up again and I am getting an error:

Cannot call member function without object.

I am calling like:

FxString text = table.GetEntry(o         


        
相关标签:
5条回答
  • 2021-02-13 07:45

    Your method isn't static, and so it must be called from an instance (sort of like the error is saying). If your method doesn't require access to any other instance variables or methods, you probably just want to declare it static. Otherwise, you'll have to obtain the correct instance and execute the method on that instance.

    0 讨论(0)
  • 2021-02-13 07:51

    You need to declare the function static in your class declaration. e.g.

    class IC_Utility {
       // ...
    
       static void CP_StringToPString(FxString& inString, FxUChar *outString);
    
       // ...
    };
    
    0 讨论(0)
  • 2021-02-13 08:02

    "static" is the right answer. or, you can pass it a NULL "this" pointer if it's not used in the function:

    ((IC_Utility*)NULL)->CP_StringToPString(...);
    
    0 讨论(0)
  • 2021-02-13 08:04

    If you've written the CP_StringToPString function, you need to declare it static:

    static void IC_Utility::CP_StringToPString( FxString& inString, FxUChar *outString)
    

    Alternatively, if it's a function in third-party code, you need to declare an IC_Utility object to call it on:

    IC_Utility u;
    u.CP_StringToPString(text, &outDescription1[0] );
    
    0 讨论(0)
  • 2021-02-13 08:05

    You have to declare the function with the 'static' keyword:

    class IC_Utility {
        static void CP_StringToPString( FxString& inString, FxUChar *outString);
    
    0 讨论(0)
提交回复
热议问题