C: “invalid use of undefined type ‘struct X’ & dereferencing pointer to incomplete type” errors

后端 未结 5 1836
天命终不由人
天命终不由人 2021-01-18 04:18

I\'ve been perusing similar questions to mine for a couple of days but still haven\'t found a solution. Thanks any any help:

I have two files, one containing methods

5条回答
  •  一向
    一向 (楼主)
    2021-01-18 04:29

    Alternatively, if you do want to totally hide the implementation of your fraction structure, you can have, in fraction.h:

    typedef struct fraction* fractionRef;
    

    and the actual declaration of your struct fraction in the fraction.c file.

    However as you do hide the implementation, you must also define function for all the actions you can issue on a fraction, like, getting the value of numerator and denominator, i.e. writing things like:

    get_numerator(f);
    

    instead of:

    f->num;
    

提交回复
热议问题