954,487 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Cannot instantiate a 2D vector in a class

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 > & __thiscall std::vector >,class std::allocator > > >::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)

Goshutu
Newbie Poster
20 posts since Oct 2010
Reputation Points: 10
Solved Threads: 0
 

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();
}
Moschops
Practically a Master Poster
620 posts since Sep 2008
Reputation Points: 258
Solved Threads: 117
 

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.

Goshutu
Newbie Poster
20 posts since Oct 2010
Reputation Points: 10
Solved Threads: 0
 

Which compiler are you using?

Moschops
Practically a Master Poster
620 posts since Sep 2008
Reputation Points: 258
Solved Threads: 117
 

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.

Goshutu
Newbie Poster
20 posts since Oct 2010
Reputation Points: 10
Solved Threads: 0
 
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++

jmichae3
Junior Poster
105 posts since Jul 2011
Reputation Points: 14
Solved Threads: 11
 

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.

Goshutu
Newbie Poster
20 posts since Oct 2010
Reputation Points: 10
Solved Threads: 0
 

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

jmichae3
Junior Poster
105 posts since Jul 2011
Reputation Points: 14
Solved Threads: 11
 

In a comment on the code i have said, that i have included in stdafx.h.
Guys, i have come across with a similar problem, now it is with , 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,class std::allocator >::operator*(void)const " (??D?$_String_const_iterator@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QBEABDXZ)


Please, somebody help!

Goshutu
Newbie Poster
20 posts since Oct 2010
Reputation Points: 10
Solved Threads: 0
 

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.

Goshutu
Newbie Poster
20 posts since Oct 2010
Reputation Points: 10
Solved Threads: 0
 

This question has already been solved

Post: Markdown Syntax: Formatting Help
You
View similar articles that have also been tagged: