Visual C ++ binding error when trying inline functions

When I tried to embed a function in Visual C ++ (2008 Express), I got a binding error, after carefully checking the code, I found that the function I'm trying to inline throws an exception ... if I delete the throwing exception, the binding error goes away, maybe Anyone explain why this is so?

int com_ximpleware::FastIntBuffer::intAt(int index){
    if (index < 0 || index > size - 1) {
       throw InvalidArgumentException("invalid index range in FastIntBuffer intAt()");
    }
    return ((int *) al->get(index>>exp))[index & r];
}

The exaxt error is shown below:

intHash.obj : error LNK2019: unresolved external symbol "public: int __thiscall com_ximpleware::FastIntBuffer::intAt(int)" (?intAt@FastIntBuffer@com_ximpleware@@QAEHH@Z) referenced in function __catch$?isUnique@IntHash@com_ximpleware@@QAE_NH@Z$0
1>C:\new_cvs\cpp_test1\Debug\cpp_test1.exe : fatal error LNK1120: 1 unresolved externals

One more thing, this function was called otherwise normally, the calling part of the function was not included.

+3
source share
1 answer

You will need to put your definition in the header file.

A built-in member function can be defined in two ways:

  • Define a member function in the class itself.
  • - - , -, - inline , :

class ClassA
{
public:
    void f();
};

inline void ClassA::f()
{
}

.cpp, - .cpp , " " (++ FAQ Lite) .

, - , . Visual ++ 2005, .

, , , .cpp. , , inline . inline, , ​​ . , , .

+9

Source: https://habr.com/ru/post/1739070/


All Articles