Sign in to follow this  
Geou

Major Vector problems... please help ASAP _

Recommended Posts

First off, I apologize for my recent influx of threads, but this is really urgent. These are the errors that I got in my program: ------ Build started: Project: Puzzle Trouble, Configuration: Debug Win32 ------ Compiling... main.cpp c:\program files\microsoft visual studio 9.0\vc\include\xutility(2967) : error C2784: 'bool std::operator ==(const std::vector<_Ty,_Alloc> &,const std::vector<_Ty,_Alloc> &)' : could not deduce template argument for 'const std::vector<_Ty,_Alloc> &' from 'const Orb' c:\program files\microsoft visual studio 9.0\vc\include\vector(1303) : see declaration of 'std::operator ==' c:\program files\microsoft visual studio 9.0\vc\include\xutility(3020) : see reference to function template instantiation 'bool std::_Equal<_InIt1,std::_Vector_const_iterator<_Ty,_Alloc>,std::forward_iterator_tag>(_InIt1,_InIt1,_InIt2,_InItCats,std::_Range_checked_iterator_tag)' being compiled with [ _InIt1=std::_Vector_const_iterator<Orb,std::allocator<Orb>>, _Ty=Orb, _Alloc=std::allocator<Orb>, _InIt2=std::_Vector_const_iterator<Orb,std::allocator<Orb>>, _InItCats=std::forward_iterator_tag ] c:\program files\microsoft visual studio 9.0\vc\include\xutility(3031) : see reference to function template instantiation 'bool std::_Equal<std::_Vector_const_iterator<_Ty,_Alloc>,_InIt2>(_InIt1,_InIt1,_InIt2,std::random_access_iterator_tag,std::_Range_checked_iterator_tag)' being compiled with [ _Ty=Orb, _Alloc=std::allocator<Orb>, _InIt2=std::_Vector_const_iterator<Orb,std::allocator<Orb>>, _InIt1=std::_Vector_const_iterator<Orb,std::allocator<Orb>> ] c:\program files\microsoft visual studio 9.0\vc\include\vector(1307) : see reference to function template instantiation 'bool std::equal<std::_Vector_const_iterator<_Ty,_Alloc>,std::_Vector_const_iterator<_Ty,_Alloc>>(_InIt1,_InIt1,_InIt2)' being compiled with [ _Ty=Orb, _Alloc=std::allocator<Orb>, _InIt1=std::_Vector_const_iterator<Orb,std::allocator<Orb>>, _InIt2=std::_Vector_const_iterator<Orb,std::allocator<Orb>> ] c:\documents and settings\administrator\my documents\visual studio 2008\projects\puzzle trouble\puzzle trouble\main.cpp(118) : see reference to function template instantiation 'bool std::operator ==<Orb,std::allocator<_Ty>>(const std::vector<_Ty> &,const std::vector<_Ty> &)' being compiled with [ _Ty=Orb ] c:\program files\microsoft visual studio 9.0\vc\include\xutility(2967) : error C2784: 'bool std::operator ==(const std::istream_iterator<_Ty,_Elem,_Traits,_Diff> &,const std::istream_iterator<_Ty,_Elem,_Traits,_Diff> &)' : could not deduce template argument for 'const std::istream_iterator<_Ty,_Elem,_Traits,_Diff> &' from 'const Orb' c:\program files\microsoft visual studio 9.0\vc\include\iterator(266) : see declaration of 'std::operator ==' c:\program files\microsoft visual studio 9.0\vc\include\xutility(2967) : error C2784: 'bool std::operator ==(const std::basic_string<_Elem,_Traits,_Alloc> &,const _Elem *)' : could not deduce template argument for 'const std::basic_string<_Elem,_Traits,_Alloc> &' from 'const Orb' c:\program files\microsoft visual studio 9.0\vc\include\string(90) : see declaration of 'std::operator ==' c:\program files\microsoft visual studio 9.0\vc\include\xutility(2967) : error C2784: 'bool std::operator ==(const _Elem *,const std::basic_string<_Elem,_Traits,_Alloc> &)' : could not deduce template argument for 'const _Elem *' from 'const Orb' c:\program files\microsoft visual studio 9.0\vc\include\string(80) : see declaration of 'std::operator ==' c:\program files\microsoft visual studio 9.0\vc\include\xutility(2967) : error C2784: 'bool std::operator ==(const std::basic_string<_Elem,_Traits,_Alloc> &,const std::basic_string<_Elem,_Traits,_Alloc> &)' : could not deduce template argument for 'const std::basic_string<_Elem,_Traits,_Alloc> &' from 'const Orb' c:\program files\microsoft visual studio 9.0\vc\include\string(70) : see declaration of 'std::operator ==' c:\program files\microsoft visual studio 9.0\vc\include\xutility(2967) : error C2784: 'bool std::operator ==(const std::istreambuf_iterator<_Elem,_Traits> &,const std::istreambuf_iterator<_Elem,_Traits> &)' : could not deduce template argument for 'const std::istreambuf_iterator<_Elem,_Traits> &' from 'const Orb' c:\program files\microsoft visual studio 9.0\vc\include\streambuf(548) : see declaration of 'std::operator ==' c:\program files\microsoft visual studio 9.0\vc\include\xutility(2967) : error C2784: 'bool std::operator ==(const std::allocator<_Ty> &,const std::allocator<_Other> &) throw()' : could not deduce template argument for 'const std::allocator<_Ty> &' from 'const Orb' c:\program files\microsoft visual studio 9.0\vc\include\xmemory(173) : see declaration of 'std::operator ==' c:\program files\microsoft visual studio 9.0\vc\include\xutility(2967) : error C2784: 'bool std::operator ==(const std::reverse_iterator<_RanIt> &,const std::reverse_iterator<_RanIt2> &)' : could not deduce template argument for 'const std::reverse_iterator<_RanIt> &' from 'const Orb' c:\program files\microsoft visual studio 9.0\vc\include\xutility(2220) : see declaration of 'std::operator ==' c:\program files\microsoft visual studio 9.0\vc\include\xutility(2967) : error C2784: 'bool std::operator ==(const std::_Revranit<_RanIt,_Base> &,const std::_Revranit<_RanIt2,_Base2> &)' : could not deduce template argument for 'const std::_Revranit<_RanIt,_Base> &' from 'const Orb' c:\program files\microsoft visual studio 9.0\vc\include\xutility(2024) : see declaration of 'std::operator ==' c:\program files\microsoft visual studio 9.0\vc\include\xutility(2967) : error C2784: 'bool std::operator ==(const std::pair<_Ty1,_Ty2> &,const std::pair<_Ty1,_Ty2> &)' : could not deduce template argument for 'const std::pair<_Ty1,_Ty2> &' from 'const Orb' c:\program files\microsoft visual studio 9.0\vc\include\utility(68) : see declaration of 'std::operator ==' c:\program files\microsoft visual studio 9.0\vc\include\xutility(2967) : error C2676: binary '==' : 'const Orb' does not define this operator or a conversion to a type acceptable to the predefined operator I did everything I could do stop things, including taking out all references entirely. But the errors keep popping up... I've only got an hour left to finish this, and so any help is IMMENSELY appreciated. Here's my source:
// First, I'm including the headers. SDL is for the graphics, sounds, and keyboard input.
#include "SDL/SDL.h"
#include "SDL/SDL_gfxPrimitives.h"
#include <cmath>
#include <string>
#include <vector>
#include <iostream>

// Now, the global variables.
const int WINDOW_WIDTH = 640;
const int WINDOW_HEIGHT = 384;
const char* WINDOW_TITLE = "Puzzle Trouble!";

int level = 0;
int highScore = 0;

// And now, the key part: the classes and functions.
// Here's the class for the individual orbs.
class Orb {
	public:
		Orb(bool lit); // Constructor
		void Change(); // Changes from lit to unlit, or vice-versa
		void drawOrb(int x, int y) const; // Draw the actual orb

	private:
		bool m_lit;
};

Orb::Orb(bool lit) {
	m_lit = lit;
}

inline void Orb::Change() {
	m_lit = !m_lit;
}

void Orb::drawOrb(int x, int y) const {
	if (m_lit)
		filledEllipseRGBA(SDL_GetVideoSurface(), x - 10, y - 10, x + 10, y + 10,
			70, 130, 180, 255);
	else
		ellipseRGBA(SDL_GetVideoSurface(), x - 10, y - 10, x + 10, y + 10,
			70, 130, 180, 255);
}

// Here's the class for the example board.
class ExampleBoard {
	public:
		ExampleBoard(const std::vector<Orb>& exBoard); // Constructor
		void displayBoard() const; // Display the board
		std::vector<Orb> m_exBoard; // The board itself
};

ExampleBoard::ExampleBoard(const std::vector<Orb>& exBoard) {
	m_exBoard = exBoard;
}

void ExampleBoard::displayBoard() const {
	// Draw the orbs.
	int j = 0;
	for (std::vector<Orb>::const_iterator iter = m_exBoard.begin();
		iter != m_exBoard.end(); ++iter) {
			iter->drawOrb(((j % 5)* 20) + 10, ((j / 5) * 20) + 30);
			++j;
	}
	// Draw the vertical lines.
	for (int i = 0; i < 4; ++i) {
		int properX = ((i % 5) * 20) + 33;
		boxRGBA(SDL_GetVideoSurface(), properX, 22, properX + 3, 113, 0, 0, 0, 255);
	}
	// Draw the horizontal lines.
	for (int i = 0; i < 4; ++i) {
		int properY = ((i / 5) * 20) + 27;
		boxRGBA(SDL_GetVideoSurface(), 7, properY, 103, properY + 3, 0, 0, 0, 255);
	}
}

// Here's the class for your board.
class Board {
	public:
		Board(const std::vector<Orb> board); // Constructor
		void displayBoard() const; // Display the board
		bool isDone(std::vector<Orb> exBoard) const; // Checks to see if the board is complete
		std::vector<Orb> m_board; // The board itself
};

Board::Board(const std::vector<Orb> board) {
	m_board = board;
}

void Board::displayBoard() const {
	// Draw the orbs.
	int j = 0;
	for (std::vector<Orb>::const_iterator iter = m_board.begin();
		iter != m_board.end(); ++iter) {
			iter->drawOrb(((j % 5)* 20) + 310, ((j / 5) * 20) + 30);
			++j;
	}
	// Draw the vertical lines.
	for (int i = 0; i < 4; ++i) {
		int properX = ((i % 5) * 20) + 33 + 300;
		boxRGBA(SDL_GetVideoSurface(), properX, 22, properX + 3, 113, 0, 0, 0, 255);
	}
	// Draw the horizontal lines.
	for (int i = 0; i < 4; ++i) {
		int properY = ((i / 5) * 20) + 27;
		boxRGBA(SDL_GetVideoSurface(), 307, properY, 403, properY + 3, 0, 0, 0, 255);
	}
}

bool Board::isDone(std::vector<Orb> exBoard) const {
	if (m_board == exBoard) {
		++level;
		return true;
	} else {
		return false;
	}
}

class Indicator {
	public:
		Indicator(int pos = 0, int x = 310, int y = 30);
		void Move(int direction);
		void DrawSelf();
		void UpdatePosition();
		void Alter(std::vector<Orb> board);
	private:
		int m_position;
		int m_x;
		int m_y;
};

Indicator::Indicator(int pos, int x, int y) {}

void Indicator::DrawSelf() {
	boxRGBA(SDL_GetVideoSurface(), m_x - 12, m_y - 12, m_x + 12, m_y + 12, 255, 0, 0, 255);
}

void Indicator::Move(int direction) {
	switch (direction) {
		case 1: if (m_position % 5 != 4)
					m_position += 1;
				break;
		case 2: if (m_position % 5 != 0)
					m_position -= 1;
				break;
		case 3: if (m_position > 4)
					m_position -= 5;
				break;
		case 4: if (m_position < 20)
					m_position += 5;
				break;
	}
	UpdatePosition();
}

void Indicator::UpdatePosition() {
	m_x = ((m_position % 5)* 20) + 310;
	m_y = ((m_position / 5) * 20) + 30;
}

void Indicator::Alter(std::vector<Orb> board) {
	board[m_position].Change();
	if (m_position > 4) {
		board[m_position - 5].Change();
		if (m_position % 5 != 4)
			board[m_position - 4].Change();
		if (m_position % 5 != 0)
			board[m_position - 6].Change();
	}
	if (m_position < 20) {
		board[m_position + 5].Change();
		if (m_position % 5 != 4)
			board[m_position + 6].Change();
		if (m_position % 5 != 0)
			board[m_position + 4].Change();
	}
	if (m_position % 5 != 4)
		board[m_position + 1].Change();
	if (m_position % 5 != 0)
		board[m_position - 1].Change();
}

int main(int argc, char **argv)
{
      SDL_Init( SDL_INIT_VIDEO );

   SDL_Surface* screen = SDL_SetVideoMode( WINDOW_WIDTH, WINDOW_HEIGHT, 0,
      SDL_HWSURFACE | SDL_DOUBLEBUF );
   SDL_WM_SetCaption( WINDOW_TITLE, 0 );

   SDL_Surface* bitmap = SDL_LoadBMP("pt-room.bmp");

   // Part of the bitmap that we want to draw
   SDL_Rect source;
   source.x = 0;
   source.y = 0;
   source.w = 640;
   source.h = 384;

   // Part of the screen we want to draw the sprite to
   SDL_Rect destination;
   destination.x = 0;
   destination.y = 0;
   destination.w = 640;
   destination.h = 384;

   SDL_Event event;
   bool gameRunning = true;

   // The game loop.
   while (gameRunning) {
      if (SDL_PollEvent(&event)) {
         if (event.type == SDL_QUIT) {
            gameRunning = false;
         }
         if (event.type == SDL_KEYDOWN) {
            SDLKey keyPressed = event.key.keysym.sym;
   Indicator icon;
            switch (keyPressed) {
			   case SDLK_ESCAPE:
				  gameRunning = false;
				  break;
			   case SDLK_LEFT:
				  icon.Move(2);
				  break;
			   case SDLK_RIGHT:
				  icon.Move(1);
				  break;
			   case SDLK_UP:
				  icon.Move(3);
				  break;
			   case SDLK_DOWN:
				  icon.Move(4);
				  break;
			}
         }
	  }
	  SDL_FillRect(screen, NULL, SDL_MapRGB(screen->format, 0, 0, 0));
      SDL_BlitSurface(bitmap, &source, screen, &destination);
      SDL_Flip(screen);
   }

   SDL_FreeSurface(bitmap);

   SDL_Quit();

   return 0;
}



Should I just try to use an array instead? [Edited by - Geou on February 22, 2008 5:35:41 AM]

Share this post


Link to post
Share on other sites
Looks like you haven't learned how to correct errors yet.

Rule number one of correcting errors: when something breaks, immediately stop writing or changing code. Anything you do might make things worse (by creating even larger errors), make correcting the error harder (by hiding its original causes behind the modification), or simply be a lot of painful and useless work. The action of removing all references in the hope of making things better can be described as voodoo programming, and I am making efforts here to stay polite.

Now that this particular detail is out of the way, let's get to Rule number two of correcting errors: understanding the cause. In this case, the error is here:
if (m_board == exBoard)
Even if the error message is too hairy to understand, you can still manage to get through by asking yourself, why should this line work? In short, try to prove that the line you wrote should compile, including every detail of the explanation of why.

Here, the proof would be along the lines of:

  • The vector header is included (check it) and the Orb class is defined (check it) above that point.

  • This is a member function of class Board (check it). The class Board has a member variable named m_board (check it), which is a vector of Orb (check it). There is no local variable named m_board (check it). Thus the identifier m_board refers to a vector of Orb.

  • The function takes an argument of type vector of Orb named exBoard (check it). It contains no other local variable of the same name (check it). Thus, the identifier exBoard refers to a vector of Orb.

  • The expression m_board == exBoard invokes operator== for two vectors, which is defined (check it) as long as the Orb class defines an operator== itself (check it).


Since the latter property is false (there is no operator== for your Orb class), you now understand the error and can correct it accordingly.

Share this post


Link to post
Share on other sites
Your next error will be this:
void Alter(std::vector<Orb> board);


You're likely to find that something doesn't work just right. Alter() changes the copy of vector, then discards the changes.

If you want to change the original board, you'll need to pass by reference:
void Alter(std::vector<Orb> & board);



Share this post


Link to post
Share on other sites
Quote:
Original post by Geou
but this is really urgent.


Why?

Quote:
I've only got an hour left to finish this


Oh, is this an assignment? We don't do homework here. Anyway, it's best to learn not to procrastinate.

Share this post


Link to post
Share on other sites
Haha, no, this is most definitely not homework. Thanks for the replies; I'll make sure to keep that style of correcting errors in mind.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this