Unresolved Externals in C++ When Using Vectors and Find

Unresolved externals in C++ when using vectors and find

I found another forum post, where somebody seems to have reported the same exact problem that you are having. Please check to see if you have

_DEBUG

defined either in your project settings (under C/C++ -- Preprocessor) or somewhere in your code (or include files).

It looks as if std::vector thinks you are building a debug build, when you are in fact creating a release build.

I hope this helps.

Unresolved external symbol error while using vectors defined in a header file

You do not have a definition for this vector:

extern std::vector<myClass> abc;

An extern declaration only tells the compiler that the object exists and it is defined somewhere. But you haven't defined it anywhere.

Add this at global namespace scope in one (and only one!) of your .cpp files:

std::vector<myClass> abc;

Actually, considering that you are not using abc from different translation units (i.e. .cpp files) you do not need the extern declaration at all. Just place your vector in main.cpp, since that is the only place where you are using it.

Also, avoid using directives, especially at namespace scope (since it easily leads to nasty name clashes with entities from the Standard Library):

using namespace std; // THIS IS BAD, DON'T DO IT

Considering that you are qualifying the names of entities from the std namespace already, you don't really need the above.

What are the unresolved externals?

You've declared swapper

// templated swap function  Swaps two items in a vector of any type
template <class CType>
void swapper (CType& a, CType & b);

but you never define it. So, when your program calls swapper, the compiler expects that a definition will be provided at link time. The linker tries to find the symbol (i.e., the function), but doesn't find it.

Same deal with the rest of your undeclared functions. To fix them, you'll need to write the appropriate functions.

Unresolved external symbol of constructer when using STL vectors

The compilation unit with main sees only this declaration

class A {
public:
A();
};

and indeed the constructor is not defined.

The declaration of the class A in the module a.cpp breaks the one definition rule. That is the class declared in a.cpp is not the same as the class declared in a.h.

In the case of this definition of the module a.cpp

#include "a.h"

A::A() {}

the both compilation units have the same class declaration and for this class there is defined the constructor.

Passing C++ vector to method results in unresolved externals

It looks like you declared VectorTest() as a trackManager member function in the header but then defined it as a free function in the cpp. This results in two unrelated functions with the same name. If you try to call VectorTest() without qualifications from inside a trackManager member function, the resolver will (sensibly) prefer the version that is also a trackManager member over the free function. But since that one doesn't have a definition, the linker can't figure out what to do with it and you get an error.

To fix this, either move the declaration out of the body of trackManager (if you want it to be a free function), or write the definition as void trackManager::VectorTest(...) (if you want it to be a member).

Vector of class type results in Unresolved external symbol error LNK2019

I see the following issues:

  1. There is no definition of Winner::Winner(std::string). That explains the linker error. In fact, I don't see definitions of any of the member functions of Winner.
  2. What is _Pop_back_n()? It's not part of the std::vector that I know of. Is it a platform specific extension?

Unresolved external symbol but the function is defined and implemented

Thanks sugar for the answer. I deleted both header and .cpp files and readded them, and it worked like a charm. I suppose I have added either header or .cpp file just by directly adding a new file to the header/source folder instead of adding it to the project (RMB click on the project > add new item).



Related Topics



Leave a reply



Submit