Quantcast
Channel: Programming Forums
Viewing all articles
Browse latest Browse all 51036

cast error when accessing map<pair<int,int>,bool[4]>

$
0
0
I'm trying to set up a data-structure that can access and add arrays of four booleans when given a two-dimensional coordinate in the form of pair<int,int>.

code:
#include <map>
#include <iostream>
#include <algorithm>
using namespace std;

class Data{
private:
	map<pair<int,int>,bool[4]> datamap;
public:
	bool* get(pair<int,int> in){
		return datamap.at(in);
	}
	void add(pair<int,int> in, bool b[4]){
		copy(b,b+4,datamap[in]);
	}
};

int main(){
	Data d;
	bool b[] = {true,false,true,false};
	d.add(make_pair(0,0),B)/>/>/>/>;
	cout<<d.get(make_pair(0,0))<<endl;
	cin.get();
}


But when I try to compile it, I get an error that makes no sence.

error:
error C2440: '<function-style-cast>' : cannot convert from 'int' to 'bool [4]'	c:\program files (x86)\microsoft visual studio 11.0\vc\include\map	198	1	robotTwo



Which points me to the 9th line in this snippet from include\map:
mapped_type& operator[](const key_type& _Keyval)
	{	// find element matching _Keyval or insert with default mapped
	iterator _Where = this->lower_bound(_Keyval);
	if (_Where == this->end()
		|| this->_Getcomp()(_Keyval, this->_Key(_Where._Mynode())))
		_Where = this->insert(_Where,
			pair<key_type, mapped_type>(
				_Keyval,
				mapped_type()));
	return (_Where->second);
	}


which is gibberish to me.

Can someone tell me what is going on?

entire output:
1>------ Build started: Project: robotTwo, Configuration: Debug Win32 ------
1>  main.cpp
1>c:\program files (x86)\microsoft visual studio 11.0\vc\include\map(198): error C2440: '<function-style-cast>' : cannot convert from 'int' to 'bool [4]'
1>          There are no conversions to array types, although there are conversions to references or pointers to arrays
1>          c:\program files (x86)\microsoft visual studio 11.0\vc\include\map(191) : while compiling class template member function 'bool (&std::map<_Kty,_Ty>::operator [](const std::pair<_Ty1,_Ty2> &))[4]'
1>          with
1>          [
1>              _Kty=std::pair<int,int>,
1>              _Ty=bool [4],
1>              _Ty1=int,
1>              _Ty2=int
1>          ]
1>          f:\school\taalderwiskunde\robottwo\robottwo\main.cpp(14) : see reference to function template instantiation 'bool (&std::map<_Kty,_Ty>::operator [](const std::pair<_Ty1,_Ty2> &))[4]' being compiled
1>          with
1>          [
1>              _Kty=std::pair<int,int>,
1>              _Ty=bool [4],
1>              _Ty1=int,
1>              _Ty2=int
1>          ]
1>          f:\school\taalderwiskunde\robottwo\robottwo\main.cpp(8) : see reference to class template instantiation 'std::map<_Kty,_Ty>' being compiled
1>          with
1>          [
1>              _Kty=std::pair<int,int>,
1>              _Ty=bool [4]
1>          ]
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========


Viewing all articles
Browse latest Browse all 51036

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>