0

So I made simple static library LogCon with such code in LogCon.cpp:

#include "LogCon.h"
namespace LogCon
{
        static bool NOT(bool a)
        {
        return !a;
        }
}

and LogCon.h:

namespace LogCon 
{
class MyLogCon
{
public:
        static bool NOT(bool a);
};
}

It was compiled fine, so I decided to make console app for this MyLogCon.cpp:

#include "LogCon.h"
#include <iostream>
using namespace std;

int main()
{   
    bool a=true;
    cout << LogCon::MyLogCon::NOT(a);
    return 0;
}

Previously added and linked this library to the project, set main console app as StartUp project. Tried to compile everything but got this:

2>MyLogCon.obj : error LNK2019: unresolved external symbol "public: static bool __cdecl LogCon::MyLogCon::NOT(bool)" (?NOT@MyLogCon@LogCon@@SA_N_N@Z) referenced in function _main

2>C:\DM\LogCon\Debug\MyLogCon.exe : fatal error LNK1120: 1 unresolved externals

I found a couple questions where was almost the same problem at stackoverflow but no one answer has helped me, so I just don't know what actually happened, please show me problem in the code why I got this error..

Community
  • 1
  • 1
Kyoko
  • 1
  • 1
  • 1
    `static bool NOT(bool a)` in "LogCon.cpp" is **not** related to `LogCon::MyLogCon::NOT (bool a)`. Did you mean to write `bool MyLogCon::NOT (bool a)` in "LogCon.cpp"? – Algirdas Preidžius Sep 11 '18 at 15:08
  • You forgot class name in function definition. Now you have `NOT` function in class `MyLogCon` **and** free function `NOT` in namespace `LogCon`. – Yksisarvinen Sep 11 '18 at 15:08

0 Answers0