I've been creating a class that defines an integer in a base other than ten. Today when I tried to compile I got a long list of errors in xstring which seemed to mostly be undefined type errors or undeclared identifier errors. I was wondering if this is a result of forgetting to include some file or me misusing a string.
intBase.cpp (the class where I would have mishandled a string)
#include "intBase.h"
intBase::intBase(int b)
{
base = b;
num = 0;
}
intBase::intBase(std::string n, int b)
{
base = b;
setNum(n);
}
int intBase::getBase() const
{
return base;
}
void intBase::setBase(int b)
{
base = b;
}
std::string intBase::getNum() const
{
int expo = 0, n, numTemp = num;
std::string result = "";
char ch;
while (num > int(pow(base, expo)))
{
expo++;
}
expo--;
while (expo >= 0)
{
n = int(numTemp / pow(base, expo));
ch = convert(n, false);
numTemp -= int(n * pow(base, expo));
result += ch;
expo--;
}
return result;
}
void intBase::setNum(std::string n)
{
char ch;
int expo, temp;
num = 0;
expo = 0;
while (n.size() > 0)
{
ch = n[n.size() - 1];
temp = convert(ch, true);
num += int(temp * pow(base, expo));
expo++;
n = n.substr(0, n.size() - 1);
}
}
int intBase::getNumTen() const
{
return num;
}
void intBase::setNumTen(int n)
{
num = n;
}
intBase intBase::add(const intBase& iBase) const
{
intBase IB(1);
if (getBase() > iBase.getBase())
{
IB.setBase(base);
}
else
{
IB.setBase(base);
}
IB.setNumTen(getNumTen() + iBase.getNumTen());
return IB;
}
intBase intBase::operator+(const intBase& iBase) const
{
return add(iBase);
}
std::ostream& operator<<(std::ostream& output, const intBase& iBase)
{
output << iBase.getNum();
return output;
}
// takes a character and returns its base ten conversion if bool is true
// takes a base-ten integer and returns its character conversion if bool is false
int intBase::convert(int x, bool letter) const
{
int result;
if (letter)
{
if (x >= 48 && x <= 57)
result = x - 48;
else if (x >= 97 && x <= 122)
result = x - 87;
else if (x >= 65 && x <= 90)
result = x - 29;
else
result = -1;
}
else
{
if (x >= 0 && x <= 9)
result = x + 48;
else if (x >= 10 && x <= 35)
result = x + 87;
else if (x >= 36 && x <= 61)
result = x + 29;
else
result = -1;
}
return result;
}
intBase.h
#pragma once
#include <string>
#include <cmath>
class intBase
{
public:
intBase(int b);
intBase(std::string n, int b);
int getBase() const;
void setBase(int b);
std::string getNum() const;
void setNum(std::string n);
int getNumTen() const;
void setNumTen(int n);
intBase add(const intBase& iBase) const;
intBase operator+(const intBase& iBase) const;
friend std::ostream& operator<<(std::ostream& output, const intBase& iBase);
private:
int convert(int x, bool y) const;
int num, base;
};
test.cpp
#include <iostream>
#include "intBase.h"
#include <string>
using namespace std;
int main()
{
int base;
string numTemp;
cout << "enter the base of your number: ";
cin >> base;
intBase num(base);
cout << "enter a number in base " << base << ": ";
cin >> numTemp;
num.setNum(numTemp);
cout << num.getNumTen() << endl;
cout << num << endl;
cout << num + num << endl;
system("pause");
return 0;
}
error log
1>------ Build started: Project: numBaseTest, Configuration: Debug Win32 ------
1>intBase.cpp
1>C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.23.28105\include\xstring(435,23): error C2027: use of undefined type 'std::basic_ostream<char,std::char_traits<char>>'
1>C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.23.28105\include\iosfwd(216): message : see declaration of 'std::basic_ostream<char,std::char_traits<char>>'
1>C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.23.28105\include\xstring(4519): message : see reference to function template instantiation 'std::basic_ostream<char,std::char_traits<char>> &std::_Insert_string<char,std::char_traits<char>,unsigned int>(std::basic_ostream<char,std::char_traits<char>> &,const _Elem *const ,const _SizeT)' being compiled
1>C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.23.28105\include\xstring(4519): message : with
1>C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.23.28105\include\xstring(4519): message : [
1>C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.23.28105\include\xstring(4519): message : _Elem=char,
1>C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.23.28105\include\xstring(4519): message : _SizeT=unsigned int
1>C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.23.28105\include\xstring(4519): message : ]
1>E:\college\numBaseTest\numBaseTest\numBaseTest\intBase.cpp(104): message : see reference to function template instantiation 'std::basic_ostream<char,std::char_traits<char>> &std::operator <<<char,std::char_traits<char>,std::allocator<char>>(std::basic_ostream<char,std::char_traits<char>> &,const std::basic_string<char,std::char_traits<char>,std::allocator<char>> &)' being compiled
1>C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.23.28105\include\xstring(435,1): error C2065: 'iostate': undeclared identifier
1>C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.23.28105\include\xstring(435,31): error C2146: syntax error: missing ';' before identifier '_State'
1>C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.23.28105\include\xstring(435,31): error C2065: '_State': undeclared identifier
1>C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.23.28105\include\xstring(435,49): error C2027: use of undefined type 'std::basic_ostream<char,std::char_traits<char>>'
1>C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.23.28105\include\iosfwd(216): message : see declaration of 'std::basic_ostream<char,std::char_traits<char>>'
1>C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.23.28105\include\xstring(435,1): error C2065: 'goodbit': undeclared identifier
1>C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.23.28105\include\xstring(438,1): error C2027: use of undefined type 'std::basic_ostream<char,std::char_traits<char>>'
1>C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.23.28105\include\iosfwd(216): message : see declaration of 'std::basic_ostream<char,std::char_traits<char>>'
1>C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.23.28105\include\xstring(441,1): error C2027: use of undefined type 'std::basic_ostream<char,std::char_traits<char>>'
1>C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.23.28105\include\iosfwd(216): message : see declaration of 'std::basic_ostream<char,std::char_traits<char>>'
1>C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.23.28105\include\xstring(444,29): error C2027: use of undefined type 'std::basic_ostream<char,std::char_traits<char>>'
1>C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.23.28105\include\iosfwd(216): message : see declaration of 'std::basic_ostream<char,std::char_traits<char>>'
1>C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.23.28105\include\xstring(444,1): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.23.28105\include\xstring(444,36): error C2146: syntax error: missing ';' before identifier '_Ok'
1>C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.23.28105\include\xstring(444,36): error C3861: '_Ok': identifier not found
1>C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.23.28105\include\xstring(446,10): error C2065: '_Ok': undeclared identifier
1>C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.23.28105\include\xstring(447,9): error C2065: '_State': undeclared identifier
1>C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.23.28105\include\xstring(447,28): error C2027: use of undefined type 'std::basic_ostream<char,std::char_traits<char>>'
1>C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.23.28105\include\iosfwd(216): message : see declaration of 'std::basic_ostream<char,std::char_traits<char>>'
1>C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.23.28105\include\xstring(447,1): error C2065: 'badbit': undeclared identifier
1>C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.23.28105\include\xstring(450,1): error C2027: use of undefined type 'std::basic_ostream<char,std::char_traits<char>>'
1>C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.23.28105\include\iosfwd(216): message : see declaration of 'std::basic_ostream<char,std::char_traits<char>>'
1>C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.23.28105\include\xstring(450,39): error C2027: use of undefined type 'std::basic_ostream<char,std::char_traits<char>>'
1>C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.23.28105\include\iosfwd(216): message : see declaration of 'std::basic_ostream<char,std::char_traits<char>>'
1>C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.23.28105\include\xstring(450,1): error C2065: 'adjustfield': undeclared identifier
1>C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.23.28105\include\xstring(450,64): error C2027: use of undefined type 'std::basic_ostream<char,std::char_traits<char>>'
1>C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.23.28105\include\iosfwd(216): message : see declaration of 'std::basic_ostream<char,std::char_traits<char>>'
1>C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.23.28105\include\xstring(450,1): error C2065: 'left': undeclared identifier
1>C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.23.28105\include\xstring(452,1): error C2027: use of undefined type 'std::basic_ostream<char,std::char_traits<char>>'
1>C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.23.28105\include\iosfwd(216): message : see declaration of 'std::basic_ostream<char,std::char_traits<char>>'
1>C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.23.28105\include\xstring(452,1): error C2660: 'std::_Narrow_char_traits<char,int>::eq_int_type': function does not take 1 arguments
1>C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.23.28105\include\xstring(401,38): message : see declaration of 'std::_Narrow_char_traits<char,int>::eq_int_type'
1>C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.23.28105\include\xstring(453,21): error C2065: '_State': undeclared identifier
1>C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.23.28105\include\xstring(453,40): error C2027: use of undefined type 'std::basic_ostream<char,std::char_traits<char>>'
1>C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.23.28105\include\iosfwd(216): message : see declaration of 'std::basic_ostream<char,std::char_traits<char>>'
1>C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.23.28105\include\xstring(453,1): error C2065: 'badbit': undeclared identifier
1>C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.23.28105\include\xstring(459,13): error C2065: '_State': undeclared identifier
1>C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.23.28105\include\xstring(459,32): error C2027: use of undefined type 'std::basic_ostream<char,std::char_traits<char>>'
1>C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.23.28105\include\iosfwd(216): message : see declaration of 'std::basic_ostream<char,std::char_traits<char>>'
1>C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.23.28105\include\xstring(459,1): error C2065: 'goodbit': undeclared identifier
1>C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.23.28105\include\xstring(460,1): error C2027: use of undefined type 'std::basic_ostream<char,std::char_traits<char>>'
1>C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.23.28105\include\iosfwd(216): message : see declaration of 'std::basic_ostream<char,std::char_traits<char>>'
1>C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.23.28105\include\xstring(461,13): error C2065: '_State': undeclared identifier
1>C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.23.28105\include\xstring(461,32): error C2027: use of undefined type 'std::basic_ostream<char,std::char_traits<char>>'
1>C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.23.28105\include\iosfwd(216): message : see declaration of 'std::basic_ostream<char,std::char_traits<char>>'
1>C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.23.28105\include\xstring(461,1): error C2065: 'badbit': undeclared identifier
1>C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.23.28105\include\xstring(464,1): error C2027: use of undefined type 'std::basic_ostream<char,std::char_traits<char>>'
1>C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.23.28105\include\iosfwd(216): message : see declaration of 'std::basic_ostream<char,std::char_traits<char>>'
1>C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.23.28105\include\xstring(464,1): error C2660: 'std::_Narrow_char_traits<char,int>::eq_int_type': function does not take 1 arguments
1>C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.23.28105\include\xstring(401,38): message : see declaration of 'std::_Narrow_char_traits<char,int>::eq_int_type'
1>C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.23.28105\include\xstring(465,21): error C2065: '_State': undeclared identifier
1>C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.23.28105\include\xstring(465,40): error C2027: use of undefined type 'std::basic_ostream<char,std::char_traits<char>>'
1>C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.23.28105\include\iosfwd(216): message : see declaration of 'std::basic_ostream<char,std::char_traits<char>>'
1>C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.23.28105\include\xstring(465,1): error C2065: 'badbit': undeclared identifier
1>C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.23.28105\include\xstring(471,1): error C2027: use of undefined type 'std::basic_ostream<char,std::char_traits<char>>'
1>C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.23.28105\include\iosfwd(216): message : see declaration of 'std::basic_ostream<char,std::char_traits<char>>'
1>C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.23.28105\include\xstring(472,1): error C2027: use of undefined type 'std::basic_ostream<char,std::char_traits<char>>'
1>C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.23.28105\include\iosfwd(216): message : see declaration of 'std::basic_ostream<char,std::char_traits<char>>'
1>C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.23.28105\include\xstring(472,9): error C2027: use of undefined type 'std::basic_ostream<char,std::char_traits<char>>'
1>C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.23.28105\include\iosfwd(216): message : see declaration of 'std::basic_ostream<char,std::char_traits<char>>'
1>C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.23.28105\include\xstring(472,1): error C2065: 'badbit': undeclared identifier
1>C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.23.28105\include\xstring(475,1): error C2027: use of undefined type 'std::basic_ostream<char,std::char_traits<char>>'
1>C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.23.28105\include\iosfwd(216): message : see declaration of 'std::basic_ostream<char,std::char_traits<char>>'
1>test.cpp
1>Generating Code...
1>C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.23.28105\include\xstring(475,20): error C2065: '_State': undeclared identifier
1>Done building project "numBaseTest.vcxproj" -- FAILED.
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
Thank you for all your help in advance.
You are missing an include to sstream. Add it to the top of intBase.h:
#pragma once
#include <sstream>
#include <string>
#include <cmath>
Have the following code which compiles and runs fine in Visual C++ 2013, and the C++14 standard on http://cpp.sh. However, on Visual C++ 2017 ( ver 15.9.3 ), it gives an error message... which is maybe a bug?
Code is:
#include <vector>
#include <algorithm>
#include <iostream>
using namespace std;
int main(int argc, char* argv[])
{
vector<long> v1 = {1}, v2 = {9};
swap<vector<long>>(v1, v2);
cout << "v1.front(): " << v1.front() << endl;
cout << "v2.front(): " << v2.front() << endl;
return 0;
}
I should note that if I comment out swap() function, then it compiles and runs ok. The error messages are all resulting from the call to swap().
Error messages are:
maptest.cpp
C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\VC\Tools\MSVC\14.16.27023\include\vector(2048): error C2039: '_Alloc': is not a member of 'std::vector<long,std::allocator<_Ty>>'
with
[
_Ty=long
]
maptest.cpp(9): note: see declaration of 'std::vector<long,std::allocator<_Ty>>'
with
[
_Ty=long
]
C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\VC\Tools\MSVC\14.16.27023\include\vector(2096): note: see reference to class template instantiation 'std::_Vb_iter_base<_Alvbase_wrapped>' being compiled
with
[
_Alvbase_wrapped=std::vector<long,std::allocator<long>>
]
maptest.cpp(11): note: see reference to class template instantiation 'std::_Vb_reference<std::vector<long,std::allocator<_Ty>>>' being compiled
with
[
_Ty=long
]
C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\VC\Tools\MSVC\14.16.27023\include\vector(2048): error C2061: syntax error: identifier '_Alloc'
C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\VC\Tools\MSVC\14.16.27023\include\vector(2049): error C2065: '_Alvbase': undeclared identifier
C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\VC\Tools\MSVC\14.16.27023\include\vector(2049): error C2923: 'std::allocator_traits': '_Alvbase' is not a valid template type argument for parameter '_Alloc'
C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\VC\Tools\MSVC\14.16.27023\include\vector(2049): error C2955: 'std::allocator_traits': use of class template requires template argument list
C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\VC\Tools\MSVC\14.16.27023\include\xmemory0(903): note: see declaration of 'std::allocator_traits'
C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\VC\Tools\MSVC\14.16.27023\include\vector(2049): error C2039: 'size_type': is not a member of 'std::allocator_traits<_Alloc>'
C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\VC\Tools\MSVC\14.16.27023\include\vector(2049): error C2061: syntax error: identifier 'size_type'
C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\VC\Tools\MSVC\14.16.27023\include\vector(2050): error C2065: '_Alvbase': undeclared identifier
C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\VC\Tools\MSVC\14.16.27023\include\vector(2050): error C2923: 'std::allocator_traits': '_Alvbase' is not a valid template type argument for parameter '_Alloc'
C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\VC\Tools\MSVC\14.16.27023\include\vector(2050): error C2955: 'std::allocator_traits': use of class template requires template argument list
C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\VC\Tools\MSVC\14.16.27023\include\xmemory0(903): note: see declaration of 'std::allocator_traits'
C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\VC\Tools\MSVC\14.16.27023\include\vector(2050): error C2039: 'difference_type': is not a member of 'std::allocator_traits<_Alloc>'
C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\VC\Tools\MSVC\14.16.27023\include\vector(2050): error C2061: syntax error: identifier 'difference_type'
C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\VC\Tools\MSVC\14.16.27023\include\vector(2051): error C2065: '_Alvbase': undeclared identifier
C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\VC\Tools\MSVC\14.16.27023\include\vector(2051): error C2923: 'std::_Rebind_alloc_t': '_Alvbase' is not a valid template type argument for parameter '_Alloc'
C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\VC\Tools\MSVC\14.16.27023\include\vector(2058): error C2061: syntax error: identifier '_Sizet'
C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\VC\Tools\MSVC\14.16.27023\include\vector(2065): error C2061: syntax error: identifier '_Sizet'
C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\VC\Tools\MSVC\14.16.27023\include\vector(2072): error C2061: syntax error: identifier '_Sizet'
C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\VC\Tools\MSVC\14.16.27023\include\vector(2089): error C3646: '_Myoff': unknown override specifier
C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\VC\Tools\MSVC\14.16.27023\include\vector(2089): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
std::swap is overloaded for std::vector as
template< class T, class Alloc>
void swap(vector<T,Alloc>& lhs, vector<T,Alloc>& rhs);
The correct template arguments for your given vector would be T=long, Alloc = std::allocator<long>. The proper way to call swap (or almost any other templated function) on an std::vector is to simply drop the explicit template argument specification altogether and let template argument deduction do its work.
i'm trying to integrate the SymbolicC++ Library into an already existing solution. My specifications are as followed: Visual Studio 2010 RTM on a Windows 7 OS.
Now my problem:
I already have a solution where I want to integrate a function with symblic variables. There is another previously integrated library (The OMPL "Open Motion Planning Library). If i try to include the symbolicc++.h it fails to compile the solution by these errors:
Error 10 error C2825: '_Fty': must be a class or namespace when followed by '::' c:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\include\xxresult 28`
Error 11 error C2903: 'result' : symbol is neither a class template nor a function template c:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\include\xxresult 28
Error 12 error C2039: 'result' : is not a member of '`global namespace'' c:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\include\xxresult 28
Error 13 error C2143: syntax error : missing ';' before '<' c:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\include\xxresult 28
Error 14 error C2039: 'type' : is not a member of '`global namespace'' c:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\include\xxresult 28
Error 15 error C2238: unexpected token(s) preceding ';' c:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\include\xxresult 28
Error 16 error C2039: '_Type' : is not a member of 'std::tr1::_Result_type2<__formal,_Fty,_Arg0,_Arg1>' c:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\include\xxresult 40
Error 17 error C2146: syntax error : missing ';' before identifier '_Type' c:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\include\xxresult 40
Error 18 error C4430: missing type specifier - int assumed. Note: C++ does not support default-int c:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\include\xxresult 40
Error 19 error C2602: 'std::tr1::_Result_of2<_Fty,_Farg0,_Farg1>::_Type' is not a member of a base class of 'std::tr1::_Result_of2<_Fty,_Farg0,_Farg1>' c:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\include\xxresult 40
Error 20 error C2868: 'std::tr1::_Result_of2<_Fty,_Farg0,_Farg1>::_Type' : illegal syntax for using-declaration; expected qualified-name c:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\include\xxresult 40
Error 21 error C2678: binary '==' : no operator found which takes a left-hand operand of type 'std::tr1::_Bind_fty<_Fty,_Ret,_BindN>' (or there is no acceptable conversion) D:\Software\RobotKitV3.0\SensorPluginMotionPlanner\Zusatz\ompl_4_RK\RK_ServerSensor_ompl\RK_ServerSensor_ompl\ServerSensor_ompl.cpp 2587
I am quite sure there is some issue between the two libraries. But i'm not getting it to work properly.
There is one line (which is referred to the Error 21), when I change it from this:
if(bind(serverSocket, (sockaddr*) &addressServer, sizeof(addressServer)) == SOCKET_ERROR)
To this:
if(::bind(serverSocket, (sockaddr*) &addressServer, sizeof(addressServer)) == SOCKET_ERROR)
I don't have these errors anymore! But when i try to start the .exe it fails
with this error:
The application was unable to start correctly (0xc000007b). Click OK to close the application
unless i exclude the line:
#include <symbolicc++.h>
Has somebody an idea to get this work? It's so frustrating that i try to implement the symbolicc++.h since 5 days and can't execute my solution.
Edit:
So I made some progress. If I just comment out everything except this code below there is no error anymore.
#include "stdafx.h"
#include <iostream>
#include <conio.h>
#include <windows.h>
#include <winsock.h>
#include <fstream>
#include <iostream>
#include <string>
#include <WinBase.h>
#include "..\..\SymbolicC++\include\symbolicc++.h"
#include "ServerSensor_ompl.h"
#include <ompl/base/SpaceInformation.h>
#include <ompl/base/spaces/SE3StateSpace.h>
#include <ompl/base/spaces/SE2StateSpace.h>
#include <ompl/base/spaces/SO2StateSpace.h>
#include <ompl/geometric/planners/rrt/RRTConnect.h>
#include <ompl/geometric/SimpleSetup.h>
#include <ompl/config.h>
#include <ompl/geometric/planners/rrt/RRT.h>
#include <ompl/geometric/planners/rrt/RRTConnect.h>
#include <ompl/geometric/planners/rrt/RRTStar.h>
Symbolic Test("Test");
namespace ob = ompl::base;
namespace og = ompl::geometric;
namespace ob_Con_WP = ompl::base;
namespace og_Con_WP = ompl::geometric;
namespace ob_Con_RC = ompl::base; // Robot_Cell
namespace og_Con_RC = ompl::geometric; // Robot_Cell
WSADATA wsa;
struct sockaddr_in addressServer;
int commSocket, serverSocket;
bool RK_active = true;
int m_bufferLength = 0;
int m_bufferLength2 = 0;
const size_t BufferSize = 100000;
char m_buffer[BufferSize];
char m_buffer2[BufferSize];
int Trial_Cart = 0;
int Trial_Joint = 0;
int Trial_Constraint_WP = 0;
int Trial_Constraint_RC = 0;
int Trial_General = 0;
bool Have_Exact_Solution;
std::fstream f;
int countCalls = 0;
int countCallLimit = 1000;
double Constraint_Bounds[2][6];
ob::StateSpacePtr space_Joint(new ob::RealVectorStateSpace(6));
ob::StateSpacePtr space_Cart(new ob::SE3StateSpace);
ob_Con_WP::StateSpacePtr space_Constraint_WP(new ob_Con_WP::RealVectorStateSpace(6));
ob_Con_RC::StateSpacePtr space_Constraint_RC(new ob_Con_RC::RealVectorStateSpace(6));
ob_Con_RC::SpaceInformationPtr si(new ob_Con_RC::SpaceInformation(space_Constraint_RC));
int _tmain(int argc, _TCHAR* argv[])
{
std::cout << "OMPL version: " << OMPL_VERSION << std::endl;
std::cout << std::endl << std::endl;
system("pause");
}
But for example if I try to put this line below into my code the same error (0xc000007B) occurs when I try to execute.
og::SimpleSetup ss_Cart(space_Cart);
#include <iostream>
#include <iomanip>
using namespace std;
double distance(double, double);
int main ()
{
double rate, time, distanceValue;
cout << fixed << showpoint << setprecision(1);
cout << "Enter rate" << endl;
cin >> rate;
cout << "Enter time" << endl;
cin >> time;
distanceValue = distance(rate, time);
cout << "The distance is " << distanceValue << endl;
}
double distance (double num1, double num2)
{
return num1 * num2;
}
when I try to compile it I see a long list of errors I don't what's wrong here! also if I change the method from double to int value it works well!! why??
the following error:
*> C:\Users\kifcaliph\Desktop\starting
out with c++\Chapter6>cl 06_012.cpp
06_012 Microsoft (R) 32-bit C/C++
Optimizing Compiler Version
16.00.30319.01 for 80x86 Copyright (C) Microsoft Corporation. All rights
reserved.
cl : Command line warning D9024 :
unrecognized source file type
'06_012', object file assumed
06_012.cpp C:\Program Files
(x86)\Microsoft Visual Studio
10.0\VC\INCLUDE\xlocale(323) : warning C4530: C++ exception handler used,
but unwind semantics are not enabled.
Specify /EHsc C:\Program Files
(x86)\Microsoft Visual Studio
10.0\VC\INCLUDE\xutility(373) : error C2825: '_Iter': must be a class or
namespace when followed by '::'
06_012.cpp(20) : see reference to class template instantiation
'std::iterator_traits<_Iter>' being
compiled
with
[
_Iter=double
] C:\Program Files (x86)\Microsoft Visual Studio
10.0\VC\INCLUDE\xutility(373) : error C2039: 'iterator_category' : is not a
member of 'global namespace''
C:\Program Files (x86)\Microsoft
Visual Studio
10.0\VC\INCLUDE\xutility(373) : error C2146: syntax error : missing ';' b
efore identifier 'iterator_category'
C:\Program Files (x86)\Microsoft
Visual Studio
10.0\VC\INCLUDE\xutility(373) : error C2602: 'std::iterator_traits<_Iter>
::iterator_category' is not a member
of a base class of
'std::iterator_traits<_Iter>'
with
[
_Iter=double
]
C:\Program Files (x86)\Microsoft Visual Studio
10.0\VC\INCLUDE\xutility(373) : see declaration of 'std::iterator
_traits<_Iter>::iterator_category'
with
[
_Iter=double
] C:\Program Files (x86)\Microsoft Visual Studio
10.0\VC\INCLUDE\xutility(373) : error C2868: 'std::iterator_traits<_Iter>
::iterator_category' : illegal syntax
for using-declaration; expected
qualified-name
with
[
_Iter=double
] C:\Program Files (x86)\Microsoft Visual Studio
10.0\VC\INCLUDE\xutility(374) : error C2825: '_Iter': must be a class or
namespace when followed by '::'
C:\Program Files (x86)\Microsoft
Visual Studio
10.0\VC\INCLUDE\xutility(374) : error C2039: 'value_type' : is not a memb er
of 'global namespace'' C:\Program
Files (x86)\Microsoft Visual Studio
10.0\VC\INCLUDE\xutility(374) : error C2146: syntax error : missing ';' b
efore identifier 'value_type'
C:\Program Files (x86)\Microsoft
Visual Studio
10.0\VC\INCLUDE\xutility(374) : error C2602: 'std::iterator_traits<_Iter>
::value_type' is not a member of a
base class of
'std::iterator_traits<_Iter>'
with
[
_Iter=double
]
C:\Program Files (x86)\Microsoft Visual Studio
10.0\VC\INCLUDE\xutility(374) : see declaration of 'std::iterator
_traits<_Iter>::value_type'
with
[
_Iter=double
] C:\Program Files (x86)\Microsoft Visual Studio
10.0\VC\INCLUDE\xutility(374) : error C2868: 'std::iterator_traits<_Iter>
::value_type' : illegal syntax for
using-declaration; expected
qualified-name
with
[
_Iter=double
] C:\Program Files (x86)\Microsoft Visual Studio
10.0\VC\INCLUDE\xutility(375) : error C2825: '_Iter': must be a class or
namespace when followed by '::'
C:\Program Files (x86)\Microsoft
Visual Studio
10.0\VC\INCLUDE\xutility(375) : error C2039: 'difference_type' : is not a
member of 'global namespace''
C:\Program Files (x86)\Microsoft
Visual Studio
10.0\VC\INCLUDE\xutility(375) : error C2146: syntax error : missing ';' b
efore identifier 'difference_type'
C:\Program Files (x86)\Microsoft
Visual Studio
10.0\VC\INCLUDE\xutility(375) : error C2602: 'std::iterator_traits<_Iter>
::difference_type' is not a member of
a base class of
'std::iterator_traits<_Iter>'
with
[
_Iter=double
]
C:\Program Files (x86)\Microsoft Visual Studio
10.0\VC\INCLUDE\xutility(375) : see declaration of 'std::iterator
_traits<_Iter>::difference_type'
with
[
_Iter=double
] C:\Program Files (x86)\Microsoft Visual Studio
10.0\VC\INCLUDE\xutility(375) : error C2868: 'std::iterator_traits<_Iter>
::difference_type' : illegal syntax
for using-declaration; expected
qualified-name
with
[
_Iter=double
] C:\Program Files (x86)\Microsoft Visual Studio
10.0\VC\INCLUDE\xutility(377) : error C2825: '_Iter': must be a class or
namespace when followed by '::'
C:\Program Files (x86)\Microsoft
Visual Studio
10.0\VC\INCLUDE\xutility(377) : error C2039: 'pointer' : is not a member of
'global namespace'' C:\Program Files
(x86)\Microsoft Visual Studio
10.0\VC\INCLUDE\xutility(377) : error C2146: syntax error : missing ';' b
efore identifier 'pointer' C:\Program
Files (x86)\Microsoft Visual Studio
10.0\VC\INCLUDE\xutility(377) : error C2602: 'std::iterator_traits<_Iter>
::pointer' is not a member of a base
class of 'std::iterator_traits<_Iter>'
with
[
_Iter=double
]
C:\Program Files (x86)\Microsoft Visual Studio
10.0\VC\INCLUDE\xutility(377) : see declaration of 'std::iterator
_traits<_Iter>::pointer'
with
[
_Iter=double
] C:\Program Files (x86)\Microsoft Visual Studio
10.0\VC\INCLUDE\xutility(377) : error C2868: 'std::iterator_traits<_Iter>
::pointer' : illegal syntax for
using-declaration; expected
qualified-name
with
[
_Iter=double
] C:\Program Files (x86)\Microsoft Visual Studio
10.0\VC\INCLUDE\xutility(378) : error C2825: '_Iter': must be a class or
namespace when followed by '::'
C:\Program Files (x86)\Microsoft
Visual Studio
10.0\VC\INCLUDE\xutility(378) : error C2039: 'reference' : is not a membe r
of '`global namespace'' C:\Program
Files (x86)\Microsoft Visual Studio
10.0\VC\INCLUDE\xutility(378) : error C2146: syntax error : missing ';' b
efore identifier 'reference'
C:\Program Files (x86)\Microsoft
Visual Studio
10.0\VC\INCLUDE\xutility(378) : error C2602: 'std::iterator_traits<_Iter>
::reference' is not a member of a base
class of 'std::iterator_traits<_Iter>'
with
[
_Iter=double
]
C:\Program Files (x86)\Microsoft Visual Studio
10.0\VC\INCLUDE\xutility(378) : see declaration of 'std::iterator
_traits<_Iter>::reference'
with
[
_Iter=double
] C:\Program Files (x86)\Microsoft Visual Studio
10.0\VC\INCLUDE\xutility(378) : error C2868: 'std::iterator_traits<_Iter>
::reference' : illegal syntax for
using-declaration; expected
qualified-name
with
[
_Iter=double
]
C:\Users\kifcaliph\Desktop\starting
out with c++\Chapter6>*
I'm guessing (since you didn't bother to actually show us the errors in question) that there's an ambiguity error between std::distance and ::distance that's coming into play because of your using directive. Fully qualify ::distance to force your function to be called, or get rid of the using directive and either fully qualify everything or add a using declaration for each of the symbols inside namespace std that you intend to use.
Also, you misspelled distanceValue as distancValue in the last line of main.
You are seeing an unfortunate side effect of using namespace std;. There is a function called std::distance; since you used using namespace std; it takes precedence over your own distance function.
The solution is to not use using namespace std;, and instead reference std::cout, std::setprecision, etc individually. You can also import specific identifiers from std:
using std::cout;
using std::setprecision;
using std::fixed;
using std::showpoint;
using std::cin;
using std::endl;
Or you can continue using using namespace std;, but explicitly request your own distance with ::distance - this requests distance from the empty namespace specifically (not recommended; if anything is added to std this could break again).
Also, distancValue is a typo.
It'll be ambiguity between std::distance and your ::distance - either fully qualify the call, or dont include the whole of the std namespace.
The error is that you wrote:
cout << "The distance is " << distancValue << endl;
instead of:
cout << "The distance is " << distanceValue << endl;
You see, there is a little 'a' in distance that you missed, fix it and it will work well.
And be careful next time :)
When I try to use my iterator class
template<class T>
class list
{
public:
class iterator;
};
template<class T>
class list<T>::iterator
{
//stuff
};
as a return type in an operator overloading,
template<class T>
class list<T>::iterator
{
public:
iterator& operator++();
protected:
list* lstptr;
};
template<class T>
iterator& list<T>::iterator::operator++()
{
(this->lstptr)->current = ((this->lstptr)->current)->next;
return this;
}
I get these errors:
s:\jeffrey_\my_freeware_games\o\resources\container class\container(spec- o)\container_def.h(213) : error C2143: syntax error : missing ';' before '&'
s:\jeffrey_\my_freeware_games\o\resources\container class\container(spec- o)\container_def.h(213) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
s:\jeffrey_\my_freeware_games\o\resources\container class\container(spec- o)\container_def.h(213) : error C2065: 'T' : undeclared identifier
c:\program files\microsoft visual studio 9.0\vc\include\codeanalysis\sourceannotations.h(235) : error C2039: 'Yes' : is not a member of 'vc_attributes'
c:\program files\microsoft visual studio 9.0\vc\include\codeanalysis\sourceannotations.h(235) : error C2065: 'Yes' : undeclared identifier
c:\program files\microsoft visual studio 9.0\vc\include\codeanalysis\sourceannotations.h(236) : error C2039: 'No' : is not a member of 'vc_attributes'
c:\program files\microsoft visual studio 9.0\vc\include\codeanalysis\sourceannotations.h(236) : error C2065: 'No' : undeclared identifier
c:\program files\microsoft visual studio 9.0\vc\include\codeanalysis\sourceannotations.h(237) : error C2039: 'Maybe' : is not a member of 'vc_attributes'
c:\program files\microsoft visual studio 9.0\vc\include\codeanalysis\sourceannotations.h(237) : error C2065: 'Maybe' : undeclared identifier
c:\program files\microsoft visual studio 9.0\vc\include\codeanalysis\sourceannotations.h(240) : error C2039: 'NoAccess' : is not a member of 'vc_attributes'
c:\program files\microsoft visual studio 9.0\vc\include\codeanalysis\sourceannotations.h(240) : error C2065: 'NoAccess' : undeclared identifier
c:\program files\microsoft visual studio 9.0\vc\include\codeanalysis\sourceannotations.h(241) : error C2039: 'Read' : is not a member of 'vc_attributes'
c:\program files\microsoft visual studio 9.0\vc\include\codeanalysis\sourceannotations.h(241) : error C2065: 'Read' : undeclared identifier
c:\program files\microsoft visual studio 9.0\vc\include\codeanalysis\sourceannotations.h(242) : error C2039: 'Write' : is not a member of 'vc_attributes'
c:\program files\microsoft visual studio 9.0\vc\include\codeanalysis\sourceannotations.h(242) : error C2065: 'Write' : undeclared identifier
c:\program files\microsoft visual studio 9.0\vc\include\codeanalysis\sourceannotations.h(243) : error C2039: 'ReadWrite' : is not a member of 'vc_attributes'
c:\program files\microsoft visual studio 9.0\vc\include\codeanalysis\sourceannotations.h(243) : error C2065: 'ReadWrite' : undeclared identifier
c:\program files\microsoft visual studio 9.0\vc\include\crtdefs.h(582) : error C2146: syntax error : missing ';' before identifier 'time_t'
c:\program files\microsoft visual studio 9.0\vc\include\crtdefs.h(2047) : error C2143: syntax error : missing ';' before 'identifier'
c:\program files\microsoft visual studio 9.0\vc\include\crtdefs.h(2047) : warning C4091: 'typedef ' : ignored on left of 'localeinfo_struct' when no variable is declared
c:\program files\microsoft visual studio 9.0\vc\include\crtdefs.h(2047) : fatal error C1075: end of file found before the left brace '{' at 'c:\program files\microsoft visual studio 9.0\vc\include\crtdefs.h(174)' was matched
NB: container_def.h is the header file for my list and iterator classes, I have no idea what souceannotations or crtdefs are.
iterator is not yet known at that point. You need to tell it it's in the list<T> class:
template<class T>
typename list<T>::iterator& list<T>::iterator::operator++() {
(this->lstptr)->current = ((this->lstptr)->current)->next;
return *this; // *this here, since this is a pointer only
}
Notice the typename is required, since list<T>::iterator is a type prefixed with a template specialization, and you need to tell the compiler about that - in spite of the fact that Visual C++ probably will accept code not putting typename before it. Omitting the typename, the compiler should assume it's not a type and should sort of produce the same error message.
You could safe yourself that hassle by putting the code straight into the class:
template<class T>
class list<T>::iterator
{
public:
iterator& operator++() {
(this->lstptr)->current = ((this->lstptr)->current)->next;
return *this; // *this here, since this is a pointer only
}
protected:
list* lstptr;
};
litb has answered your question completely. I think it worth highlighting that in an effort to make C++ easier to use, the C++ Committee has added a new syntax for the declaration of functions. The result is that you'll be able to define your function as follows (n2541) without needing the extra qualification:
template<class T>
auto list<T>::iterator::operator++()->iterator&
{
// ...
}
According to the supported feature list, GCC 4.4 already has this feature.