Hi, i am doing a multiple-file project and i come across a difficult obstacles. I want your help, DaniWeb readers on this problem, which i find very strange:

#include "stdafx.h"//i have included vector header here
#include "globals.h"
#include "functions.h"
using namespace std;
#ifndef CPIECE
#define CPIECE

class CPiece
{
//stuff...
public:
vector<vector<int>> piece;
CPiece() :piece(4,vector<int>(2))
{
//more stuff...
}

Bad news is, it does not compile. It gives me this error:

Error 32 error LNK2019: unresolved external symbol __imp___CrtDbgReportW referenced in function "public: class std::vector<int,class std::allocator<int> > & __thiscall std::vector<class std::vector<int,class std::allocator<int> >,class std::allocator<class std::vector<int,class std::allocator<int> > > >::operator[](unsigned int)" (??A?$vector@V?$vector@HV?$allocator@H@std@@@std@@V?$allocator@V?$vector@HV?$allocator@H@std@@@std@@@2@@std@@QAEAAV?$vector@HV?$allocator@H@std@@@1@I@Z)

Unresolved external symbol generally means you've not linked to the right library, or you haven't written a function you need.

The following code is fine. Can you build it?

#include <vector>
#include <iostream>

using namespace std;

class CPiece
{
public:
vector<vector<int> > piece;
CPiece() :piece(4,vector<int>(2))
    {}
};

int main()
{
  CPiece eggs;
  cout << eggs.piece.size();
}

Code like in the class definition would not compile in my case, i am afraid the problem is located somewhere deeper. As i am typing, i have changed my decision to use a vector, and i am using a normal static array, so i won`t need to use vector in this particular project.

Which compiler are you using?

It is Microsoft Visual Studio 2010.... as for today I have seen a lot of strange things with it and I feel little disappointed, but it might be my coding, it often does not realize i have made changes to the source... I even do not want to try making this array already.

Member Avatar for jmichae3
using namespace std;
int main(void) {
    vector<vector<int> > vvi; //the space is VERY important, otherwise, non-c++11
                              //compilers interpret >> as a shift op and error out.
    return 0;
}

this is a bug in the older c++ spec which was fixed in c++11/c++0x. if you want to use this style of coding, I suggest you use the seitch which turns on this mode of the compiler if it has this. gcc goes. -std=c++0x -lstdc++

No, the problem is somewhere else, MSVS 2010 does support c++11 in some ways. strange thing is, in an other project i did not have any problems with a vector of vectors.

Member Avatar for jmichae3

I didn't see ANYWHERE where you #included <vector>
did you do it in some other header?

In a comment on the code i have said, that i have included <vector> in stdafx.h.
Guys, i have come across with a similar problem, now it is with <string>, i am afraid that the problem is in the inclusion of files, will post you code of stdafx.h, tell me what else to give you, because the program is large.

// stdafx.h : include file for standard system include files,
// or project specific include files that are used frequently, but
// are changed infrequently
//

#pragma once

#include "targetver.h"

#include <stdio.h>
#include <tchar.h>


// TODO: reference additional headers your program requires here
//SDL Stuff"
#include <SDL.h>
#include <SDL_mixer.h>
#include <SDL_ttf.h>
#include <SDL_image.h>

//Standart libs:
#include <string>
#include <ctime>

//User files:
#include "CMenu.h"
#include "functions.h"
#include "globals.h"
#include "CGame.h"
#include "CHighScore.h"

Error 40 error LNK2019: unresolved external symbol __imp___CrtDbgReportW referenced in function "public: char const & __thiscall std::_String_const_iterator<char,struct std::char_traits<char>,class std::allocator<char> >::operator*(void)const " (??D?$_String_const_iterator@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QBEABDXZ)


Please, somebody help!

Well, I figured it out myself, i Googled "error LNK2019: unresolved external symbol __imp___CrtDbgReportW" and found a solution : In project properties, Configuration Properties, C/C++, Preprocessor, Preprocessor Definitions , I removed "_DEBUG". It worked and the problem disappeared.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.