I am writing a program for the selection of films to the user on the basis of the films he previously liked. The parser of the file file seemed to be working, but not the problem: it gives 6 LNK2019 errors to an unresolved external character (judging by LINK1120 there are 3 such places), something like something wrong with inline getId() const .

Error example:

Error LNK1120 Unresolved External Elements: 3 FilmSelection

C: \ Users \ Andrey \ Documents \ GitHub \ FilmSelection \ FilmSelection \ FilmSelection \ De bug \ FilmSelection.exe 1


Error LNK2019 link to unresolved external character "public: class std :: basic_string, class std :: allocator> __thiscall Channel :: getId (void) const" (? GetId @ Channel @@ QBE? AV? $ Basic_string @ DU? $ Char_traits @ D @ std @@ V? $ Allocator @ D @ 2 @@ std @@ XZ) in the function "public: class std :: shared_ptr __thiscall User :: findChannel (class std :: basic_string, class std :: allocator>) "(? findChannel @ User @@ QAE? AV? $ shared_ptr @ VChannel @@@ std @@ V? $ basic_string @ DU? $ char_traits @ D @ std @@ V? $ allocator @ D @ 2 @@ 3 @@ Z) FilmSelection C: \ Users \ Andrey \ Documents \ GitHub \ FilmSelection \ FilmSelection \ FilmSelection \ FilmSelection \ User.obj 1

 inline string Channel::getId() const; // public метод, который я вызываю через shared pointer на данный класс { return id; //id является private string } //поиск фильма, у Film есть аналогичный метод получения getId(), films - это list<shared_ptr<Film>> films //increaseLikes() увеличивает количество лайков для канала и аналогично для фильма shared_ptr<Film> Channel::findFilm(string id_film) { for (auto it = films.begin(); it != films.end(); it++) if (id_film == (*it)->getId()) { (*it)->increaseLikes(); return (*it); } return nullptr; } 

Here is the source GITHUB

  • one
    Eh, why are you the Debug and Release folders in git .. - Vladimir Gamalyan
  • one
    Try to remove inline. - free_ze
  • @free_ze helped, thanks! But why???? It’s also kind of like to do when getting data - Xambey
  • @free_ze gave an error because inline inserts the entire code at the call site, but not return in if ()? - Xambey
  • one
    @Xambey Because inline functions must be defined along with the type, i.e. in the header, similar to patterns. I kopipaschu my comments in response. - free_ze

2 answers 2

Try to remove inline .

They say it makes no sense to manually write this keyword, because modern compilers do not react to it and inline according to their own understanding.

  • Well, you would have completely copied your comments, but in the current form it does not pull on the answer, but only on the comment. Please add details, why inline needs to be removed in this case. - ixSci
  • @ixSci If you wish, you can edit other people's answers or add your own. I have no answer why, because I do not write this in response. - free_ze

The presence of the inline specifier when defining a function with an external layout (external linkage) in .cpp requires duplication of the definition of the function in all translation units where it is used:

It has been defined as the definition in each case.

Your case can be simplified to the following :

 // ah #pragma once struct A { void f(); }; 

 // a.cpp #include "ah" inline void A::f() {} 

 // main.cpp #include "ah" int main() { A a; af(); } 

The main.cpp module sees the A::f declaration (from ah ), but due to the presence of inline does not see the definition of A::f (that is, it is missing in main.cpp ). You can solve the problem:

  • either by removing the inline , and making the implementation available to other translation units;
  • or by placing in the main.cpp exact same function definition as in a.cpp .