out of practice

Greetings and salutations! I haven't programmed in about 6 years so I'm a bit out of practice. The below code throws some 162 errors in xmemory0

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
Grid::Grid(Hex* current)
{
	int run = current->calculateMapSpace(current->getXRun(), current->getYRun());
	int rowPush = 0;
	hexGrid.push_back(current);
	for (int i = 1; i < run; i++)
	{
		// check to see if i go up or down
		if (hexGrid.at(i-1)->getInBounds())
		{
			if (i % 2 == 0)
			{
				//go up
				hexGrid.push_back(new Hex(hexGrid.at(i - 1)->getXPos() + 30, hexGrid.at(i - 1)->getYPos() + 30, hexGrid.at(0)->getTool()));
				hexGrid.at(i)->setXCoor(hexGrid.at(i-1)->getXCoor() + 1);
				hexGrid.at(i)->checkbounds(hexGrid.at(0)->getXRun(), hexGrid.at(0)->getYRun());
			}
			else
			{
				//go down
				hexGrid.push_back(new Hex(hexGrid.at(i - 1)->getXPos() + 30, hexGrid.at(i - 1)->getYPos() - 30, hexGrid.at(0)->getTool()));
				hexGrid.at(i)->setXCoor(hexGrid.at(i - 1)->getXCoor() + 1);
				hexGrid.at(i)->checkbounds(hexGrid.at(0)->getXRun(), hexGrid.at(0)->getYRun());
				
			}
		}
		else
		{
			// start new row
			rowPush++;
			hexGrid.push_back(new Hex(20, 30 + (rowPush * 60), hexGrid.at(0)->getTool()));
			hexGrid.at(i)->setXCoor(1);
			hexGrid.at(i)->setYCoor(hexGrid.at(i-1)->getYCoor() + 1);
			hexGrid.at(i)->checkbounds(hexGrid.at(0)->getXRun(), hexGrid.at(0)->getYRun());
		}
	}
}

the first 5 errors in the error list are:
Error 1 error C2516: '_Alloc' : is not a legal base class c:\program files (x86)\microsoft visual studio 12.0\vc\include\xmemory0 749 1 P2
Error 2 error C2825: '_Alloc': must be a class or namespace when followed by '::' c:\program files (x86)\microsoft visual studio 12.0\vc\include\xmemory0 419 1 P2
Error 3 error C2039: 'value_type' : is not a member of '`global namespace'' c:\program files (x86)\microsoft visual studio 12.0\vc\include\xmemory0 419 1 P2
Error 4 error C2146: syntax error : missing ';' before identifier 'value_type' c:\program files (x86)\microsoft visual studio 12.0\vc\include\xmemory0 419 1 P2
Error 5 error C2602: 'std::allocator_traits<_Alloc>::value_type' is not a member of a base class of 'std::allocator_traits<_Alloc>' c:\program files (x86)\microsoft visual studio 12.0\vc\include\xmemory0 419 1 P2

what have I done wrong? Thank you in advance
I would guess that it is a missing #include . Hard to tell from this snippet.
I have found the source of my woes, however very unexpected and a bit confusing. After ensuring all the #include (Thanks again coder777) were, to the best of my knowledge, correct, I began to look at why they were there in the first place. In the header Hex.h the following makes the compiler go *KABLAM*:

std::vector<int, int> hexVect;

Though I am glad it now builds, I still seek the answers to why and how that is wrong (rather what I did to make it wrong). Below is the Hex.h in it's entirety... it's a bit messy

#ifndef HEX_H
#define HEX_H
#include <vector>
#include "SDLT.h"


class Hex
{
public:
Hex(int, int,Hex, int);
Hex(int, int, SDLT*);
Hex(int, int, SDLT*, bool);
int xPos, yPos, relation,xRun,yRun;
Hex* hexArray[6];
SDLT* tool;
SDLT* getTool();
bool inBounds;
int getXPos();
int getYPos();
bool getInBounds();
int indexSwitch(int);
int offSetXSwicth(int);
int offSetYSwitch(int);
int adjustYSwitch(int);
int sharesConncetionSwitch(int);
// std::vector<int, int> hexVect; // explodes don't use
int xCoor, yCoor;
int getXCoor();
int getYCoor();
int getXRun();
int getYRun();
int calculateMapSpace(int, int);
void setXCoor(int);
void setYCoor(int);
void checkbounds(int, int);
private:
void drawHex(int, int);
Hex* getHex();
Hex* getNode();
void setNode(Hex*);
void drawConnection(Hex);
const int xUR = 30, xDR = 30, xUL = -30, xDL = -30, yUD = 60, yUR = 30, yDR = 30, yUL = -30, yDL = -30;
// int calculateMapSpace(int, int);



};
#endif
In case you want to know why the error was what it was, std::vector is a template that takes two parameters: element type and allocator type - see docs such as http://en.cppreference.com/w/cpp/container/vector or http://www.cplusplus.com/reference/vector/vector -- when you don't deal with memory management, the allocator type is usually omitted so that the default is used.

by writing std::vector<int, int> hexVect; you told the compiler to create a vector whose element type is int and whose allocator type is int. There are many requirements on what the allocator type must be ( http://en.cppreference.com/w/cpp/concept/Allocator ), and one of that is that it must be a class with a member called value_type. Your compiler assumed that it was true and ran into errors: "'_Alloc' : is not a legal base class" and "std::allocator_traits<_Alloc>::value_type' is not a member".

When the new C++ language extension called "Concepts" becomes part of the language and library (already supported in gcc trunk for the language part, but not yet for the lbirary), the error on your vector<int, int> line would be simply "int does not meet the requirements of Allocator". Until then, learning to read template instantiation error messages is a difficult, but valuable skill.
Last edited on
Topic archived. No new replies allowed.