none
Strange compiler error C4930.

    Question

  • This function prototype gives me a C4930 error:

    CApFascioData MakeViabizzunoVersion(const CFotomDati* const pFotomDati,
                                        const CApFascioData& kApFascioIn);
    

    It then says "prototyped function not called (was a variable definition intended?)"

    Well, no, I hand the function two objects and return a third object. What is the compiler objecting to?

    The error has nothing to do with the actual definition of the function, because if I remove the definition I still get the C4930 error.


    http://www.ransen.com Cad and Graphics software

    Tuesday, January 02, 2018 10:59 AM

Answers

  • On 1/2/2018 5:59 AM, Owen Ransen wrote:

    This function prototype gives me a C4930 error:

    CApFascioData MakeViabizzunoVersion(const CFotomDati* const pFotomDati,
                                                                             const CApFascioData& kApFascioIn);
    

    It then says "prototyped function not called (was a variable definition intended?)"
    Well, no, I hand the function two objects and return a third object. What is the compiler objecting to?

    It's a warning about a prototype for a function that's never actually called. The reason this warrants a warning is the so-called most vexing parse ( https://en.wikipedia.org/wiki/Most_vexing_parse ), whereby an ambiguous syntax that could be either a variable definition or a function declaration is treated as the latter, often unexpectedly. In the example you show there's no ambiguity though, it's unmistakably a function declaration. I suppose you could safely remove it if, as the compiler claims, the function is indeed never called.

    • Marked as answer by Owen Ransen Tuesday, January 02, 2018 2:46 PM
    Tuesday, January 02, 2018 11:49 AM

All replies

  • Hello,

    how is CApFascioData defined? As the C4930 implies, this class does not have a Default constructor.

    By the way: big data classes shouldn't be used as return values, because the copy-constructor or Operator= of the class will be used. Instead use a call-by-reference varibale in the parameter list like this:

    bool MakeViabizzunoVersion(CApFascioData& kOut, const CFotomDati* const pFotomDati, const CApFascioData& kApFascioIn);

    Regards, Guido

    Tuesday, January 02, 2018 11:06 AM
  • Hello,

    how is CApFascioData defined? As the C4930 implies, this class does not have a Default constructor.

    By the way: big data classes shouldn't be used as return values, because the copy-constructor or Operator= of the class will be used. Instead use a call-by-reference varibale in the parameter list like this:

    bool MakeViabizzunoVersion(CApFascioData& kOut, const CFotomDati* const pFotomDati, const CApFascioData& kApFascioIn);

    Regards, Guido

    Thanks for the reply, but how does the error message imply that CApFascioData does not have a default constructor (which in fact it doesn't) ?

    CApFascioData is a very small class and will not cause problems methinks.

    I do use the "pass by reference" technique, but when I can I like to assign objects directly from function calls. The "pass by reference" is ugly but sometimes neccessary, I know.


    http://www.ransen.com Cad and Graphics software

    Tuesday, January 02, 2018 11:22 AM
  • Thanks for the reply, but how does the error message imply that CApFascioData does not have a default constructor (which in fact it doesn't) ?

    CApFascioData is a very small class and will not cause problems methinks.

    I do use the "pass by reference" technique, but when I can I like to assign objects directly from function calls. The "pass by reference" is ugly but sometimes neccessary, I know.


    http://www.ransen.com Cad and Graphics software

    Read the answer here: https://stackoverflow.com/questions/20264530/c-warning-c4930-prototyped-function-not-called-was-a-variable-definition-i

    C4930 implies that the default constructor is not defined.

    Even "very small" classes can cause problems if they are not defined correctly and then used in a specific way where the C++ wants special definitions.

    Who says that call-by-reference is "ugly"? It is not "ugly".

    Show us the class definition and we can help you to find out what is wrong in your class.

    Regards, Guido

    Tuesday, January 02, 2018 11:42 AM
  • On 1/2/2018 5:59 AM, Owen Ransen wrote:

    This function prototype gives me a C4930 error:

    CApFascioData MakeViabizzunoVersion(const CFotomDati* const pFotomDati,
                                                                             const CApFascioData& kApFascioIn);
    

    It then says "prototyped function not called (was a variable definition intended?)"
    Well, no, I hand the function two objects and return a third object. What is the compiler objecting to?

    It's a warning about a prototype for a function that's never actually called. The reason this warrants a warning is the so-called most vexing parse ( https://en.wikipedia.org/wiki/Most_vexing_parse ), whereby an ambiguous syntax that could be either a variable definition or a function declaration is treated as the latter, often unexpectedly. In the example you show there's no ambiguity though, it's unmistakably a function declaration. I suppose you could safely remove it if, as the compiler claims, the function is indeed never called.

    • Marked as answer by Owen Ransen Tuesday, January 02, 2018 2:46 PM
    Tuesday, January 02, 2018 11:49 AM
  • You're going to gave to help me here. It is clearly a function prototype because it has (two) typed parameters and brackets. Which part is causing me problems?

    The code is sensitive so I can't show you the CApFascioData...

    Beauty and ugliness are all in the eye of the beholder... I prefer to say

    a = Func(b)
    
    // rather than
    
    int a;
    
    Func (a,b)
    
    
    


    http://www.ransen.com Cad and Graphics software

    Tuesday, January 02, 2018 11:52 AM
  • You're going to gave to help me here. It is clearly a function prototype because it has (two) typed parameters and brackets. Which part is causing me problems?

    The code is sensitive so I can't show you the CApFascioData...

    Beauty and ugliness are all in the eye of the beholder... I prefer to say

    a = Func(b)
    
    // rather than
    
    int a;
    
    Func (a,b)
    
    


    http://www.ransen.com Cad and Graphics software

    Ok, if your class is as simple as "int", then call-by-reference does not make sense. But since I don't know how many variables and data are in your class, I suggested to use call-by-reference so that the operator= would not be called.

    I'm not really interested in the full definition of your class, only in the structure. The important things are which operators and constructors you use and if they are private or public.

    Read this how to define a class: http://www.cplusplus.com/doc/tutorial/classes2/

    Regards, Guido

    Tuesday, January 02, 2018 1:50 PM
  •  I suppose you could safely remove it if, as the compiler claims, the function is indeed never called.

    That is the odd thing. It is actually called, and works, in two different files.



    http://www.ransen.com Cad and Graphics software

    Tuesday, January 02, 2018 2:48 PM
  • On 1/2/2018 9:48 AM, Owen Ransen wrote:

     I suppose you could safely remove it if, as the compiler claims, the function is indeed never called.

    That is the odd thing. It is actually called, and works, in two different files.

    Any chance you could prepare a Minimal, Complete and Verifiable Example ( https://stackoverflow.com/help/mcve ) that reproduces the problem?

    Tuesday, January 02, 2018 3:38 PM
  • On 1/2/2018 9:48 AM, Owen Ransen wrote:

    That is the odd thing. It is actually called, and works, in two different files.

    Any chance you could prepare a Minimal, Complete and Verifiable Example ( https://stackoverflow.com/help/mcve ) that reproduces the problem?

    I'll try to get time to do it today...

    http://www.ransen.com Cad and Graphics software

    Wednesday, January 03, 2018 5:40 AM
  • I'll try to get time to do it today...

    http://www.ransen.com Cad and Graphics software

    When I brought the whole declaration of CApFascioData into the header file (instead of including it) I no longer get the error message.

    Unfortunately I don't have time to dig further, this'll have to be a mystery inside an enigma...


    http://www.ransen.com Cad and Graphics software

    • Proposed as answer by Guido Franzke Thursday, January 04, 2018 6:45 AM
    • Unproposed as answer by Owen Ransen Thursday, January 04, 2018 6:52 AM
    Wednesday, January 03, 2018 4:37 PM