Link error with really simple functions C++ on .h file

后端 未结 4 1021
离开以前
离开以前 2021-01-05 19:09

I\'ve made two functions to \'cast\' a 32/64 bit pointer into a double. The code worked when used alone (Just the .h and a .cpp including it) but when using the .h somewhere

4条回答
  •  走了就别回头了
    2021-01-05 19:31

    Put your code in a .cpp file and in the .h file just put the prototypes -

    double ptr2double(void* pv);
    void* double2ptr(double dv);
    

    Or keep the code as it is and add "inline" to each function definition which will allow you to define them in each module

    Although I don't think that your code will actually do anything very useful. it's undefined behavour to access a different member of a union than the one you used to store the data. Plus even if that "worked" I can't think how you plan to use this, you'll store a double and read 32 bits of it into a pointer (on a 32 bit machine)... How can you possibly make use of this for anything?

提交回复
热议问题