I'm trying to pinpoint where the location of this error is coming from. C2664 is a parameter conversion problem that isn't showing up as an error in my coding, but rather something that is written in xmemory0 (or at least, that's how i'm interpreting it). I understand that part of what it's complaining about is that it is being asked to convert from an allocator to a string. I'm not using an allocator in this file.
The error reads:
C2664 'std::pair<const _Kty,_Ty>::pair(std::pair<const _Kty,_Ty>
&&)': cannot convert argument 1 from
'std::vector<std::string,std::allocator<_Ty>>' to 'const std::string &'
Project1 c:\program files (x86)\microsoft visual studio
14.0\vc\include\xmemory0, Line 737
The code in question:
/*
Interpreter class implementation: utilizes the lex scanner class as
well as the expression evaluator to interpret simple statements like
read display and assignment statements
!!: indicates current problems or things that are going to be problems.
*/
#include <iostream>
#include <map>
#include <string>
#include <vector>
#include <cstdlib>
#include "lexScanner.h"
#include "expEvaluator.h"
#include "interpreter.h"
using namespace std;
void Interpreter::executeProgram(vector<string>& sourceProgram)
{
// ****************************************************
// PARSING THE INFORMATION:
// Intialize all containers for storage of broken down string components
// Resize al appropriate vectors to the size of the source program
// ****************************************************
// !!: This probably wont work. Source program is going to be magnitudes
// smaller than the amount of category tokens
// but it worked in the last programming project soooo. .. .
vectOfTokenVects myVectOfTokenVects;
vectOfCategoryVects myVectOfCategoryVects;
perLineCategoryVector myPerLineCatVect;
// Send for parsing
LexicalScanner::getLexicalInfo(sourceProgram,myVectOfTokenVects,myVectOfCategoryVects);
//Display the lexical information for user's means
cout << "Here is a preview of the source code to be executed. . \n";
// Create a string-to-float map that serves as a symbol table to maintain
// the names of variables and their values during execution
// !!: figure out how to store items in the map
floatVarValueTable varTable;
// ****************************************************
// EXECUTING A READ STATEMENT:
// Obtain numerical input from the user and
// store it properly in the corresponding variable in the map as a symbol
// table.
// ****************************************************
// Cycle through the tokens, searching for the three categories
// If the catToken is keyword AND IS read, go ahead and execute a cin
// If the catToken is keyword AND IS display, go ahead and execute a cout
// If the catToken is an assignment statement, figure out how far the
// math expression goes. Try to compute the line. Search comma to comma?
// ****************************************************
for (int i = 0; i < myVectOfCategoryVects.size(); i++)
{
// Start out with the largest net: search for keywords
for (int j = 0; j < myVectOfCategoryVects[i].size(); j++)
{
if (myVectOfCategoryVects[i][j] == KEYWORD)
{
// SCENARIO 1: READ STATEMENT
// Have the user enter the value for the variable to be added to vartable.
if ((myVectOfTokenVects[i][j] == "Read") || (myVectOfTokenVects[i][j] == "READ") || (myVectOfTokenVects[i][j] == "read"))
{
float reportedValue;
cout << "Please enter a value for: " << myVectOfTokenVects[i][j + 1] << endl;
cin >> reportedValue;
string dumpedString = myVectOfTokenVects[i][j + 1];
varTable.emplace(dumpedString, reportedValue);
}
// SCENARIO 2: DISPLAY STATEMENT
// Search the vector (token vector) for things to display.
if (myVectOfTokenVects[i][j] == "Display" || myVectOfTokenVects[i][j] == "display" || myVectOfTokenVects[i][j] == "DISPLAY")
{
// Search the vector continiously until you reach a comma or semicolon. Both comma and semicolon indicate the end of the display statement.
int currentPosition = j+1;
for (int j = currentPosition; j > myVectOfTokenVects[i].size(); i++)
{
if (myVectOfCategoryVects[i][j] != COMMA)
{
cout << myVectOfTokenVects[i][j];
}
// We've got something after the comma, prob an expression. Send it to expression evaluator
if (myVectOfCategoryVects[i][j] == COMMA)
{
expVector infixExpression;
float expValue;
// Start filling up the expression vector
for (int k = j; k > myVectOfTokenVects[i][j].size(); k++)
{
infixExpression.push_back(myVectOfTokenVects[i][k]);
}
// Take the newly formed expression vector and send it to the evaluator. It does pass by reference, so the values in the vartable and infixexpression are going to be updated
ExpressionEvaluator::infixEvaluator(infixExpression, varTable, expValue);
cout << expValue;
}
}
}
}
// ****************************************************
// SEARCHING FOR VARIABLES
// If the token in question is an assignment operator, go ahead
// and insert the item before and after it.
// Note: This leaves a hole stating that if there is a floating
// equals sign somewhere with nothing before or after it, it
// could cause a out of bounds error.
// Note: We should also check for the presence of an equation.
// Evaluate the RHS of the assignment op
if (myVectOfCategoryVects[i][j] == ASSIGNMENT_OP)
{
// SCENARIO 1: SIMPLE EVALUATION
// If it's a simple 3 part assignment statement: ie:
// name (=) value, go ahead and store it
if (myVectOfCategoryVects[i][j + 2])
{
// Make sure the assignment op has a var name
if (myVectOfCategoryVects[i][j - 1])
{
// Store both the name and value
varTable.emplace(myVectOfTokenVects[j - 1], myVectOfTokenVects[j + 1]);
}
}
}
// SCENARIO 2: COMPLEX EVALUATION
// More complex evaluation: sending the RHS to the evaluator
// NOTE: postfix evaluator needs to be fixed. .
if (myVectOfCategoryVects[i][j] == ASSIGNMENT_OP)
{
// Semicolon out of normal place, assume incoming expression
if (myVectOfCategoryVects[i][j + 2] != SEMICOLON)
{
// NOTE: The placement of this is intentional. . .it guarentees that they get cleared on OOS
expVector infixExpression;
float expValue;
// Start with whatever is before the assignment op, start adding items to the infixExpression vector. Lookout for semicolon
for (int j = 0; myVectOfCategoryVects[i][j] != SEMICOLON; i++)
{
infixExpression.push_back(myVectOfTokenVects[i][j]);
}
// Take the newly formed expression vector and send it to the evaluator. It does pass by reference, so the values in the vartable and infixexpression are going to be updated
ExpressionEvaluator::infixEvaluator(infixExpression, varTable, expValue);
}
}
}
}
}
Relative definitions:
//****************************************************************************
// define a mnemonic name for the type to store tokens of one line of statement
//****************************************************************************
typedef vector<string> perLineTokenVector;
//****************************************************************************
// define a mnemonic name for the type to store tokens of lines of statement
//****************************************************************************
typedef vector<perLineTokenVector> vectOfTokenVects;
//****************************************************************************
// define a mnemonic name for the type to store categories of tokens
// of one line of statement
//****************************************************************************
typedef vector<tokenCategory> perLineCategoryVector;
//****************************************************************************
// define a mnemonic name for the type to store categories of tokens
// of one line of statement
//****************************************************************************
typedef vector<perLineCategoryVector> vectOfCategoryVects;
edit: The error seems to reside in this area
if (myVectOfCategoryVects[i][j] == ASSIGNMENT_OP)
{
// SCENARIO 1: SIMPLE EVALUATION
// If it's a simple 3 part assignment statement: ie:
// name (=) value, go ahead and store it
if (myVectOfCategoryVects[i][j + 2]=SEMICOLON)
{
// Make sure the assignment op has a var name
if (myVectOfCategoryVects[i][j - 1] = STRING_LITERAL)
{
string stringDump = myVectOfTokenVects[i][j - 1];
// Store both the name and value
varTable.emplace(stringDump, myVectOfTokenVects[i][j + 1]);
}
}
}
Build output
1>------ Build started: Project: Project1, Configuration: Debug Win32 ------
1> interpreter.cpp
1>c:\users\alfar\google drive\school\programminglanguages\programming 4a\programming 4a vs2\project1\project1\interpreter.cpp(67): warning C4018: '<': signed/unsigned mismatch
1>c:\users\alfar\google drive\school\programminglanguages\programming 4a\programming 4a vs2\project1\project1\interpreter.cpp(70): warning C4018: '<': signed/unsigned mismatch
1>c:\users\alfar\google drive\school\programminglanguages\programming 4a\programming 4a vs2\project1\project1\interpreter.cpp(94): warning C4018: '>': signed/unsigned mismatch
1>c:\users\alfar\google drive\school\programminglanguages\programming 4a\programming 4a vs2\project1\project1\interpreter.cpp(106): warning C4018: '>': signed/unsigned mismatch
1>c:\program files (x86)\microsoft visual studio 14.0\vc\include\xmemory0(737): error C2664: 'std::pair<const _Kty,_Ty>::pair(std::pair<const _Kty,_Ty> &&)': cannot convert argument 2 from 'std::string' to 'const float &'
1> with
1> [
1> _Kty=std::string,
1> _Ty=float
1> ]
1> c:\program files (x86)\microsoft visual studio 14.0\vc\include\xmemory0(737): note: Reason: cannot convert from 'std::string' to 'const float'
1> c:\program files (x86)\microsoft visual studio 14.0\vc\include\xmemory0(737): note: No user-defined-conversion operator available that can perform this conversion, or the operator cannot be called
1> c:\program files (x86)\microsoft visual studio 14.0\vc\include\xmemory0(857): note: see reference to function template instantiation 'void std::allocator<_Other>::construct<_Objty,std::string&,std::string&>(_Objty *,std::string &,std::string &)' being compiled
1> with
1> [
1> _Other=std::_Tree_node<std::pair<const std::string,float>,void *>,
1> _Objty=std::pair<const std::string,float>
1> ]
1> c:\program files (x86)\microsoft visual studio 14.0\vc\include\xmemory0(857): note: see reference to function template instantiation 'void std::allocator<_Other>::construct<_Objty,std::string&,std::string&>(_Objty *,std::string &,std::string &)' being compiled
1> with
1> [
1> _Other=std::_Tree_node<std::pair<const std::string,float>,void *>,
1> _Objty=std::pair<const std::string,float>
1> ]
1> c:\program files (x86)\microsoft visual studio 14.0\vc\include\xmemory0(996): note: see reference to function template instantiation 'void std::allocator_traits<_Alloc>::construct<_Ty,std::string&,std::string&>(std::allocator<_Other> &,_Objty *,std::string &,std::string &)' being compiled
1> with
1> [
1> _Alloc=std::allocator<std::_Tree_node<std::pair<const std::string,float>,void *>>,
1> _Ty=std::pair<const std::string,float>,
1> _Other=std::_Tree_node<std::pair<const std::string,float>,void *>,
1> _Objty=std::pair<const std::string,float>
1> ]
1> c:\program files (x86)\microsoft visual studio 14.0\vc\include\xmemory0(995): note: see reference to function template instantiation 'void std::allocator_traits<_Alloc>::construct<_Ty,std::string&,std::string&>(std::allocator<_Other> &,_Objty *,std::string &,std::string &)' being compiled
1> with
1> [
1> _Alloc=std::allocator<std::_Tree_node<std::pair<const std::string,float>,void *>>,
1> _Ty=std::pair<const std::string,float>,
1> _Other=std::_Tree_node<std::pair<const std::string,float>,void *>,
1> _Objty=std::pair<const std::string,float>
1> ]
1> c:\program files (x86)\microsoft visual studio 14.0\vc\include\xtree(889): note: see reference to function template instantiation 'void std::_Wrap_alloc<std::allocator<_Other>>::construct<_Ty,std::string&,std::string&>(_Ty *,std::string &,std::string &)' being compiled
1> with
1> [
1> _Other=std::_Tree_node<std::pair<const std::string,float>,void *>,
1> _Ty=std::pair<const std::string,float>
1> ]
1> c:\program files (x86)\microsoft visual studio 14.0\vc\include\xtree(887): note: see reference to function template instantiation 'void std::_Wrap_alloc<std::allocator<_Other>>::construct<_Ty,std::string&,std::string&>(_Ty *,std::string &,std::string &)' being compiled
1> with
1> [
1> _Other=std::_Tree_node<std::pair<const std::string,float>,void *>,
1> _Ty=std::pair<const std::string,float>
1> ]
1> c:\program files (x86)\microsoft visual studio 14.0\vc\include\xtree(1076): note: see reference to function template instantiation 'std::_Tree_node<std::pair<const _Kty,_Ty>,void *> *std::_Tree_comp_alloc<_Traits>::_Buynode<std::string&,std::string&>(std::string &,std::string &)' being compiled
1> with
1> [
1> _Kty=std::string,
1> _Ty=float,
1> _Traits=std::_Tmap_traits<std::string,float,std::less<std::string>,std::allocator<std::pair<const std::string,float>>,false>
1> ]
1> c:\program files (x86)\microsoft visual studio 14.0\vc\include\xtree(1076): note: see reference to function template instantiation 'std::_Tree_node<std::pair<const _Kty,_Ty>,void *> *std::_Tree_comp_alloc<_Traits>::_Buynode<std::string&,std::string&>(std::string &,std::string &)' being compiled
1> with
1> [
1> _Kty=std::string,
1> _Ty=float,
1> _Traits=std::_Tmap_traits<std::string,float,std::less<std::string>,std::allocator<std::pair<const std::string,float>>,false>
1> ]
1> c:\users\alfar\google drive\school\programminglanguages\programming 4a\programming 4a vs2\project1\project1\interpreter.cpp(145): note: see reference to function template instantiation 'std::pair<std::_Tree_iterator<std::_Tree_val<std::_Tree_simple_types<std::pair<const _Kty,_Ty>>>>,bool> std::_Tree<std::_Tmap_traits<_Kty,_Ty,_Pr,_Alloc,false>>::emplace<std::string&,std::basic_string<char,std::char_traits<char>,std::allocator<char>>&>(std::string &,std::basic_string<char,std::char_traits<char>,std::allocator<char>> &)' being compiled
1> with
1> [
1> _Kty=std::string,
1> _Ty=float,
1> _Pr=std::less<std::string>,
1> _Alloc=std::allocator<std::pair<const std::string,float>>
1> ]
1> c:\users\alfar\google drive\school\programminglanguages\programming 4a\programming 4a vs2\project1\project1\interpreter.cpp(145): note: see reference to function template instantiation 'std::pair<std::_Tree_iterator<std::_Tree_val<std::_Tree_simple_types<std::pair<const _Kty,_Ty>>>>,bool> std::_Tree<std::_Tmap_traits<_Kty,_Ty,_Pr,_Alloc,false>>::emplace<std::string&,std::basic_string<char,std::char_traits<char>,std::allocator<char>>&>(std::string &,std::basic_string<char,std::char_traits<char>,std::allocator<char>> &)' being compiled
1> with
1> [
1> _Kty=std::string,
1> _Ty=float,
1> _Pr=std::less<std::string>,
1> _Alloc=std::allocator<std::pair<const std::string,float>>
1> ]
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
edit 3
It appears that the problem was with what I was passing to the emplacement function for the map. myVectOfTokenVects is a fancy string vector of string vectors. The second argument to the map.emplacement() requires a float value, of which myVectOfTokenVects cannot supply. The problem has been found.
Follow-up:
How would I go about parsing the string value to cast it to a float for map.emplacement()?
Related
I have this map that contains integers as keys that refer to sets of integers. Basically I have an std::map(int, std::set(int)).
I tried to define an iterator for the map and one for the set, but I keep getting an error when I try to point the set_iterator to a specific set in the map. I get a red line under the equality symbols that try to equate both iterators (no operator "=" matches these operands). I am using visual studio c++ 2017, and I keep getting build errors.
lines 63-70 of /mykarger.cpp
map<int, std::set<int>>::iterator graph_it;
set<string>::const_iterator set_it, set_end;
std::cout << "Vertix\tEdges\n;";
for(graph_it = mygraph.begin(); graph_it != mygraph.end(); ++graph_it) {
std::cout << graph_it->first << ":\t";
for(set_it = graph_it->second.begin();; set_it != graph_it->second.end(); ++set_it){
cout << *set_it << "\t";
}
I expect the results to print like this:
Vertex Edges
1: 2 3
2: 1 3
3: 1 2
But I get the error:
1>------ Build started: Project: mykarger, Configuration: Debug Win32 ------
1>mykarger.cpp
1>c:\users\alkamali\source\repos\mykarger\mykarger\mykarger.cpp(68): error C2679: binary '=': no operator found which takes a right-hand operand of type 'std::_Tree_const_iterator<std::_Tree_val<std::_Tree_simple_types<_Ty>>> *' (or there is no acceptable conversion)
1> with
1> [
1> _Ty=int
1> ]
1>c:\program files (x86)\microsoft visual studio\2017\community\vc\tools\msvc\14.16.27023\include\xtree(303): note: could be 'std::_Tree_const_iterator<std::_Tree_val<std::_Tree_simple_types<_Ty>>> &std::_Tree_const_iterator<std::_Tree_val<std::_Tree_simple_types<_Ty>>>::operator =(std::_Tree_const_iterator<std::_Tree_val<std::_Tree_simple_types<_Ty>>> &&)'
1> with
1> [
1> _Ty=std::basic_string<char,std::char_traits<char>,std::allocator<char>>
1> ]
1>c:\program files (x86)\microsoft visual studio\2017\community\vc\tools\msvc\14.16.27023\include\xtree(303): note: or 'std::_Tree_const_iterator<std::_Tree_val<std::_Tree_simple_types<_Ty>>> &std::_Tree_const_iterator<std::_Tree_val<std::_Tree_simple_types<_Ty>>>::operator =(const std::_Tree_const_iterator<std::_Tree_val<std::_Tree_simple_types<_Ty>>> &)'
1> with
1> [
1> _Ty=std::basic_string<char,std::char_traits<char>,std::allocator<char>>
1> ]
1>c:\users\alkamali\source\repos\mykarger\mykarger\mykarger.cpp(68): note: while trying to match the argument list '(std::_Tree_const_iterator<std::_Tree_val<std::_Tree_simple_types<_Ty>>>, std::_Tree_const_iterator<std::_Tree_val<std::_Tree_simple_types<_Ty>>> *)'
1> with
1> [
1> _Ty=std::basic_string<char,std::char_traits<char>,std::allocator<char>>
1> ]
1> and
1> [
1> _Ty=int
1> ]
1>c:\users\alkamali\source\repos\mykarger\mykarger\mykarger.cpp(69): error C2679: binary '=': no operator found which takes a right-hand operand of type 'std::_Tree_const_iterator<std::_Tree_val<std::_Tree_simple_types<_Ty>>> *' (or there is no acceptable conversion)
1> with
1> [
1> _Ty=int
1> ]
1>c:\program files (x86)\microsoft visual studio\2017\community\vc\tools\msvc\14.16.27023\include\xtree(303): note: could be 'std::_Tree_const_iterator<std::_Tree_val<std::_Tree_simple_types<_Ty>>> &std::_Tree_const_iterator<std::_Tree_val<std::_Tree_simple_types<_Ty>>>::operator =(std::_Tree_const_iterator<std::_Tree_val<std::_Tree_simple_types<_Ty>>> &&)'
1> with
1> [
1> _Ty=std::basic_string<char,std::char_traits<char>,std::allocator<char>>
1> ]
1>c:\program files (x86)\microsoft visual studio\2017\community\vc\tools\msvc\14.16.27023\include\xtree(303): note: or 'std::_Tree_const_iterator<std::_Tree_val<std::_Tree_simple_types<_Ty>>> &std::_Tree_const_iterator<std::_Tree_val<std::_Tree_simple_types<_Ty>>>::operator =(const std::_Tree_const_iterator<std::_Tree_val<std::_Tree_simple_types<_Ty>>> &)'
1> with
1> [
1> _Ty=std::basic_string<char,std::char_traits<char>,std::allocator<char>>
1> ]
1>c:\users\alkamali\source\repos\mykarger\mykarger\mykarger.cpp(69): note: while trying to match the argument list '(std::_Tree_const_iterator<std::_Tree_val<std::_Tree_simple_types<_Ty>>>, std::_Tree_const_iterator<std::_Tree_val<std::_Tree_simple_types<_Ty>>> *)'
1> with
1> [
1> _Ty=std::basic_string<char,std::char_traits<char>,std::allocator<char>>
1> ]
1> and
1> [
1> _Ty=int
1> ]
1>Done building project "mykarger.vcxproj" -- FAILED.
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
The error message is massive and it can take while to extract the relevant information, but what it boils down to is that you're trying to assign a std::set<int>::iterator to a std::set<string>::iterator.
You have
map<int, std::set<int>>::iterator graph_it;
^^^
but
set<string>::const_iterator set_it, set_end;
^^^^^^
A more modern formulation of the same loop avoids many potential problems:
for(const auto& vertex: my_graph) {
std::cout << vertex.first << ":\t";
for (const auto& edge: vertex.second)
{
std::cout << edge << " ";
}
}
First of all, I use boost library, and if it changes anything, the code is compiled on a Windows Machine.
The code itself contains a lot more of function acting upon matrices but only this one triggers the error.
Well, I am trying to transform matrix like :
{001
100
010}
To something like :
{1
3
2}
But strangely I can't compile my code and I can't find the error so I would be glad if anyone could help me.
Below the code :
using namespace boost::numeric::ublas;
typedef matrix <float, row_major, unbounded_array<float>> MATRIXf;
MATRIXf matrix_to_class (const MATRIXf inputM)
{
MATRIXf output;
for (std::size_t line = 0; line < inputM.size1(); line++)
{
for (std::size_t column = 0; column < inputM.size2(); column++)
{
if (column == 1)
{
output.insert_element(line,0.0,column);
}
}
}
return output;
}
Here is the error code:
1>c:\program files (x86)\microsoft visual studio 14.0\vc\include\xutility(2372): error C4996: 'std::copy::_Unchecked_iterators::_Deprecate': Call to 'std::copy' with parameters that may be unsafe - this call relies on the caller to check that the passed values are correct. To disable this warning, use -D_SCL_SECURE_NO_WARNINGS. See documentation on how to use Visual C++ 'Checked Iterators'
1> c:\program files (x86)\microsoft visual studio 14.0\vc\include\xutility(2372): note: see declaration of 'std::copy::_Unchecked_iterators::_Deprecate'
1> e:\c++ libraries\general\boost_1_65_0\boost\numeric\ublas\storage.hpp(204): note: see reference to function template instantiation '_OutIt *std::copy<float*,float*>(_InIt,_InIt,_OutIt)' being compiled
1> with
1> [
1> _OutIt=float *,
1> _InIt=float *
1> ]
1> e:\c++ libraries\general\boost_1_65_0\boost\numeric\ublas\storage.hpp(201): note: while compiling class template member function 'boost::numeric::ublas::unbounded_array<float,std::allocator<T>> &boost::numeric::ublas::unbounded_array<T,std::allocator<T>>::operator =(const boost::numeric::ublas::unbounded_array<T,std::allocator<T>> &)'
1> with
1> [
1> T=float
1> ]
1> e:\c++ libraries\general\boost_1_65_0\boost\numeric\ublas\matrix.hpp(310): note: see reference to function template instantiation 'boost::numeric::ublas::unbounded_array<float,std::allocator<T>> &boost::numeric::ublas::unbounded_array<T,std::allocator<T>>::operator =(const boost::numeric::ublas::unbounded_array<T,std::allocator<T>> &)' being compiled
1> with
1> [
1> T=float
1> ]
1> e:\c++ libraries\general\boost_1_65_0\boost\numeric\ublas\matrix.hpp(102): note: see reference to class template instantiation 'boost::numeric::ublas::unbounded_array<float,std::allocator<T>>' being compiled
1> with
1> [
1> T=float
1> ]
1> g:\c++ python\travail\visualstudio\visualstudio\guigui\neural net\neural net\utils.hpp(21): note: see reference to class template instantiation 'boost::numeric::ublas::matrix<float,boost::numeric::ublas::row_major,boost::numeric::ublas::unbounded_array<float,std::allocator<T>>>' being compiled
1> with
1> [
1> T=float
1> ]
1>c:\program files (x86)\microsoft visual studio 14.0\vc\include\xmemory(102): error C4996: 'std::uninitialized_copy::_Unchecked_iterators::_Deprecate': Call to 'std::uninitialized_copy' with parameters that may be unsafe - this call relies on the caller to check that the passed values are correct. To disable this warning, use -D_SCL_SECURE_NO_WARNINGS. See documentation on how to use Visual C++ 'Checked Iterators'
1> c:\program files (x86)\microsoft visual studio 14.0\vc\include\xmemory(102): note: see declaration of 'std::uninitialized_copy::_Unchecked_iterators::_Deprecate'
1> e:\c++ libraries\general\boost_1_65_0\boost\numeric\ublas\storage.hpp(94): note: see reference to function template instantiation '_FwdIt *std::uninitialized_copy<const float*,float*>(_InIt,_InIt,_FwdIt)' being compiled
1> with
1> [
1> _FwdIt=float *,
1> _InIt=const float *
1> ]
1> e:\c++ libraries\general\boost_1_65_0\boost\numeric\ublas\storage.hpp(89): note: while compiling class template member function 'boost::numeric::ublas::unbounded_array<float,std::allocator<T>>::unbounded_array(const boost::numeric::ublas::unbounded_array<T,std::allocator<T>> &)'
1> with
1> [
1> T=float
1> ]
1> e:\c++ libraries\general\boost_1_65_0\boost\numeric\ublas\matrix.hpp(162): note: see reference to function template instantiation 'boost::numeric::ublas::unbounded_array<float,std::allocator<T>>::unbounded_array(const boost::numeric::ublas::unbounded_array<T,std::allocator<T>> &)' being compiled
1> with
1> [
1> T=float
1> ]
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
Trying to locate the error brings me to the function above.
Thanks in advance.
Near the end of the first error message is the text, "To disable this warning, use -D_SCL_SECURE_NO_WARNINGS". https://msdn.microsoft.com/en-us/library/ttcz0bys.aspx has a more detailed discussion of warnings and checked iterators. In essence, Microsoft created "safe" mutations of Standard C++ functions to help developers avoid invalid iterator usage. The error message suggests that you define _SCL_SECURE_NO_WARNINGS. This can be done in the project properties C/C++/Preprocessor/Preprocessor Definitions. In a project I worked on in the past, we disabled all the "safe" versions of the functions because of the performance hit.
You may be interested in reading the above Microsoft page for more information about the checked iterator topic.
I am having trouble pushing an array to the stack. I thought this was pretty straightforward, but I've already spent too much time trying to figure this one out.
I expected to be able to push arrays just as I push ints or floats, but that is not happening.
The push command is giving me the issue. Here is my code:
#include <iostream>
#include <stack>
struct Matrix4x4
{
float data[16];
};
int main(int argc, char **argv)
{
// My original code
typedef std::stack<float[16]> myStack;
myStack modelViewStack;
myStack projectionStack;
float testMat[16] = {0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15};
modelViewStack.push(testMat); // THIS LINE GIVES ME ERRORS
////Stack initialization - This is thokra's solution
////typedef std::stack<std::vector<float[16]>> myStack;
//typedef std::stack<Matrix4x4> myStack;
//myStack modelViewStack;
//myStack projectionStack;
//
//Matrix4x4 m = {0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15};
////std::vector<float> testMat2(testMat, testMat + sizeof(testMat) / sizeof(float));
//modelViewStack.push(m);
//for(int i = 0; i<16 ; i++)
//{
// std::cout << "m data: " << m.data[i] << std::endl;
//}
//system("pause");
return 0;
}
Thanks for your help!
Here are the errors. I can't decipher them. Maybe an explanation of how to read these would be helpful too.
1>------ Build started: Project: opengl4_4, Configuration: Release Win32 ------
1> main.cpp
1>C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\include\xmemory0(606): error C2075: 'Target of operator new()' : array initialization needs curly braces
1> C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\include\xmemory0(605) : while compiling class template member function 'void std::allocator<_Ty>::construct(_Ty (*),const _Ty (&))'
1> with
1> [
1> _Ty=float [16]
1> ]
1> C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\include\xmemory0(751) : see reference to function template instantiation 'void std::allocator<_Ty>::construct(_Ty (*),const _Ty (&))' being compiled
1> with
1> [
1> _Ty=float [16]
1> ]
1> C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\include\type_traits(743) : see reference to class template instantiation 'std::allocator<_Ty>' being compiled
1> with
1> [
1> _Ty=float [16]
1> ]
1> C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\include\deque(925) : see reference to class template instantiation 'std::is_empty<_Ty>' being compiled
1> with
1> [
1> _Ty=std::allocator<float [16]>
1> ]
1> C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\include\stack(21) : see reference to class template instantiation 'std::deque<_Ty>' being compiled
1> with
1> [
1> _Ty=float [16]
1> ]
1> main.cpp(14) : see reference to class template instantiation 'std::stack<_Ty>' being compiled
1> with
1> [
1> _Ty=float [16]
1> ]
1>C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\include\xmemory0(606): fatal error C1903: unable to recover from previous error(s); stopping compilation
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
Just encapsulate the data store holding the elements of the matrix in a suitable type:
#include <stack>
struct Matrix4x4
{
float data[16];
};
int main()
{
typedef std::stack<Matrix4x4> myStack;
myStack modelViewStack;
Matrix4x4 m = {0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15};
modelViewStack.push(m);
return 0;
}
More to the point: std::stack::push will internally call push_back on the std::deque that's used as the container when you don't change the default. Essentially, when trying to construct a new element at the end of the deque the container tries to place the new element at the address which currently marks the end of the container with a placement-new. For instance, g++ implements it as follows:
template<typename _Up, typename... _Args>
void
construct(_Up* __p, _Args&&... __args)
{ ::new((void *)__p) _Up(std::forward<_Args>(__args)...); }
This effectively boils down to:
::new((void *)__p) float[16](_args); // where __p is a pointer to float[16] and _args is testMat
Trying to copy- or move-initialize a C-array is simply not legal. Even if construction succeeded for some reason, the container would try to call the destructor on an element of type float[16] when going out of scope. One can easily see, a destructor ~T[n] does not exist.
In C++11, you can push a std::array<float,16> instead of defining an additional type.
This question already has answers here:
How can I use std::maps with user-defined types as key?
(8 answers)
Closed 5 years ago.
Here is my code to to find values in a map:
bool myclass::getFreqFromCache( plVariablesConjunction& varABC, vector<plFloat>& freq )
{
std::map<plVariablesConjunction, std::vector<plFloat>>::iterator freqItr;
freqItr = freqCache.find(varABC);
if (freqItr != freqCache.end())
{
freq = freqItr->second;
return true;
}
}
"PlVariablesConjunction" is a ProBT library datatype. it contains operator "==", if two variables found same then it returns true otherwise false.
Here is error:
C:\Program Files\Microsoft Visual Studio 10.0\VC\include\xfunctional(125): error C2678: binary '<' : no operator found which takes a left-hand operand of type 'const plVariablesConjunction' (or there is no acceptable conversion)
1> E:\ProBT22\probt-spl-2.2.0-expires-20121130-vc10-dynamic-release\include\plSymbol.h(71): could be 'bool operator <(const plSymbol &,const plSymbol &)' [found using argument-dependent lookup]
1> while trying to match the argument list '(const plVariablesConjunction, const plVariablesConjunction)'
1> C:\Program Files\Microsoft Visual Studio 10.0\VC\include\xfunctional(124) : while compiling class template member function 'bool std::less<_Ty>::operator ()(const _Ty &,const _Ty &) const'
1> with
1> [
1> _Ty=plVariablesConjunction
1> ]
1> C:\Program Files\Microsoft Visual Studio 10.0\VC\include\map(71) : see reference to class template instantiation 'std::less<_Ty>' being compiled
1> with
1> [
1> _Ty=plVariablesConjunction
1> ]
1> C:\Program Files\Microsoft Visual Studio 10.0\VC\include\xtree(451) : see reference to class template instantiation 'std::_Tmap_traits<_Kty,_Ty,_Pr,_Alloc,_Mfl>' being compiled
1> with
1> [
1> _Kty=plVariablesConjunction,
1> _Ty=std::vector<plProbValue>,
1> _Pr=std::less<plVariablesConjunction>,
1> _Alloc=std::allocator<std::pair<const plVariablesConjunction,std::vector<plProbValue>>>,
1> _Mfl=false
1> ]
1> C:\Program Files\Microsoft Visual Studio 10.0\VC\include\xtree(520) : see reference to class template instantiation 'std::_Tree_nod<_Traits>' being compiled
1> with
1> [
1> _Traits=std::_Tmap_traits<plVariablesConjunction,std::vector<plProbValue>,std::less<plVariablesConjunction>,std::allocator<std::pair<const plVariablesConjunction,std::vector<plProbValue>>>,false>
1> ]
1> C:\Program Files\Microsoft Visual Studio 10.0\VC\include\xtree(659) : see reference to class template instantiation 'std::_Tree_val<_Traits>' being compiled
1> with
1> [
1> _Traits=std::_Tmap_traits<plVariablesConjunction,std::vector<plProbValue>,std::less<plVariablesConjunction>,std::allocator<std::pair<const plVariablesConjunction,std::vector<plProbValue>>>,false>
1> ]
1> C:\Program Files\Microsoft Visual Studio 10.0\VC\include\map(81) : see reference to class template instantiation 'std::_Tree<_Traits>' being compiled
1> with
1> [
1> _Traits=std::_Tmap_traits<plVariablesConjunction,std::vector<plProbValue>,std::less<plVariablesConjunction>,std::allocator<std::pair<const plVariablesConjunction,std::vector<plProbValue>>>,false>
1> ]
1> e:\probt22\work\yasin\testmmhcfinalversion\testmmhc_mi_probt_sw\mmhc\slidingWindow.h(55) : see reference to class template instantiation 'std::map<_Kty,_Ty>' being compiled
1> with
1> [
1> _Kty=plVariablesConjunction,
1> _Ty=std::vector<plProbValue>
1> ]
std::map is (usually) implemented as binary search tree, most often red-black tree. It needs linear order to be defined for key values to find correct position within a tree. That's why std::map tries to call operator< on inserted key values.
Your class doesn't provide operator<. Either define operator< for your class or provide comparison function for template: std::map<plVariablesConjunction, std::vector<plFloat>, my_comparison_function>.
To use the map class, require two, and possibly three, types for the template:
std::map <key_type, data_type, [comparison_function]>
Either you need to provide a comparison function or overload the < operator in the key class.
Notice that the comparison function is in brackets, indicating that it is optional so long as your key_type has the less-than operator, <, defined
map<> doesn't use operator== to check the inserted values. It needs a comparision via operator< for the key values.
I'm getting an error occurring in the 'xutility' class - It is locked as I did not create it
error C2582: 'operator =' function is unavailable in 'Agent'
The error points to these lines in the code:
// TEMPLATE FUNCTION move
template<class _InIt,
class _OutIt> inline
_OutIt _Move(_InIt _First, _InIt _Last,
_OutIt _Dest, _Nonscalar_ptr_iterator_tag)
{ // move [_First, _Last) to [_Dest, ...), arbitrary iterators
for (; _First != _Last; ++_Dest, ++_First)
*_Dest = _STD move(*_First); // this line has the error
return (_Dest);
}
Why is this occurring? What does it mean and how can I fix it?
EDIT - this is what I grabbed from the output, can someone help me understand this? Sorry to be a complete newbie...
1>------ Build started: Project: D3D10DEMO, Configuration: Debug Win32 ------
1> Level.cpp
1>c:\users\asher\documents\my dropbox\direct3d\d3d10demo_1.0\d3d10demo\level.cpp(449): warning C4018: '<' : signed/unsigned mismatch
1> Brain.cpp
1>c:\users\asher\documents\my dropbox\direct3d\d3d10demo_1.0\d3d10demo\brain.cpp(43): warning C4413: 'Brain::nodes' : reference member is initialized to a temporary that doesn't persist after the constructor exits
1> c:\users\asher\documents\my dropbox\direct3d\d3d10demo_1.0\d3d10demo\brain.h(34) : see declaration of 'Brain::nodes'
1>c:\users\asher\documents\my dropbox\direct3d\d3d10demo_1.0\d3d10demo\brain.cpp(43): warning C4413: 'Brain::roomNodeVectors' : reference member is initialized to a temporary that doesn't persist after the constructor exits
1> c:\users\asher\documents\my dropbox\direct3d\d3d10demo_1.0\d3d10demo\brain.h(35) : see declaration of 'Brain::roomNodeVectors'
1>c:\program files (x86)\microsoft visual studio 10.0\vc\include\xutility(2514): error C2582: 'operator =' function is unavailable in 'Agent'
1> c:\program files (x86)\microsoft visual studio 10.0\vc\include\xutility(2535) : see reference to function template instantiation '_OutIt std::_Move<_InIt,_OutIt> (_InIt,_InIt,_OutIt,std::_Nonscalar_ptr_iterator_tag)' being compiled
1> with
1> [
1> _OutIt=Agent *,
1> _InIt=Agent *
1> ]
1> c:\program files (x86)\microsoft visual studio 10.0\vc\include\vector(1170) : see reference to function template instantiation '_OutIt std::_Move<Agent*,Agent*>(_InIt,_InIt,_OutIt)' being compiled
1> with
1> [
1> _OutIt=Agent *,
1> _InIt=Agent *
1> ]
1> c:\program files (x86)\microsoft visual studio 10.0\vc\include\vector(1165) : while compiling class template member function 'std::_Vector_iterator<_Myvec> std::vector<_Ty>::erase(std::_Vector_const_iterator<_Myvec>)'
1> with
1> [
1> _Myvec=std::_Vector_val<Agent,std::allocator<Agent>>,
1> _Ty=Agent
1> ]
1> c:\users\asher\documents\my dropbox\direct3d\d3d10demo_1.0\d3d10demo\brain.h(41) : see reference to class template instantiation 'std::vector<_Ty>' being compiled
1> with
1> [
1> _Ty=Agent
1> ]
1>c:\program files (x86)\microsoft visual studio 10.0\vc\include\xutility(2514): error C2582: 'operator =' function is unavailable in 'Pickup'
1> c:\program files (x86)\microsoft visual studio 10.0\vc\include\xutility(2535) : see reference to function template instantiation '_OutIt std::_Move<_InIt,_OutIt>(_InIt,_InIt,_OutIt,std::_Nonscalar_ptr_iterator_tag)' being compiled
1> with
1> [
1> _OutIt=Pickup *,
1> _InIt=Pickup *
1> ]
1> c:\program files (x86)\microsoft visual studio 10.0\vc\include\vector(1170) : see reference to function template instantiation '_OutIt std::_Move<Pickup*,Pickup*>(_InIt,_InIt,_OutIt)' being compiled
1> with
1> [
1> _OutIt=Pickup *,
1> _InIt=Pickup *
1> ]
1> c:\program files (x86)\microsoft visual studio 10.0\vc\include\vector(1165) : while compiling class template member function 'std::_Vector_iterator<_Myvec> std::vector<_Ty>::erase(std::_Vector_const_iterator<_Myvec>)'
1> with
1> [
1> _Myvec=std::_Vector_val<Pickup,std::allocator<Pickup>>,
1> _Ty=Pickup
1> ]
1> c:\users\asher\documents\my dropbox\direct3d\d3d10demo_1.0\d3d10demo\brain.h(44) : see reference to class template instantiation 'std::vector<_Ty>' being compiled
1> with
1> [
1> _Ty=Pickup
1> ]
1> Generating Code...
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
You seem to be calling a function template of the standard library with a type Agent that cannot be move-assigned to, yet the algorithm invoked needs to do just that.
As Als said in a comment to your question, you need to show the code that invokes this algorithm.
Of course you need to provide the agent class.
Assuming C++11, you need to implement
struct Agent
{
// .... other stuff
Agent(Agent&& other) { /* ... */ }
Agent& operator=(Agent&& other) { /* ... */ return *this; }
};
which is known as the Move Assignment operator. While you're at it, you might want to implement the move constructor as they go hand-in-hand:
Agent(Agent&& other) { /* ... */ }
Recommended reading:
http://en.wikipedia.org/wiki/C%2B%2B11#Rvalue_references_and_move_constructors
http://akrzemi1.wordpress.com/2011/08/11/move-constructor/
and many others