using swap with template argument conflicts with std::vector include - c++

Today I came across a really strange behavior of the msvc2013 compiler.
After nearly an hour, I found the causing bug.
Minimal example:
#include <iostream>
#include <vector>
int main(int argc, char *argv[])
{
float f1, f2;
std::swap<float>(f1, f2);
return 0;
}
When including std::vector, I get a bunch of very strange compiler errors with msvc2013! When compiling the code with mingw the code compiles fine, just as I would expect.
The errors:
main.cpp
C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\INCLUDE\xlocale(341): warning C4530: C++ exception handler used, but unwind semantics are not enabled. Specify /EHsc
C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\INCLUDE\vector(1892): error C2825: '_Alloc': must be a class or namespace when followed by '::'
C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\INCLUDE\vector(1944): note: see reference to class template instantiation 'std::_Vb_iter_base<_Alloc>' being compiled
with
[
_Alloc=float
]
main.cpp(10): note: see reference to class template instantiation 'std::_Vb_reference<float>' being compiled
C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\INCLUDE\vector(1892): error C2510: '_Alloc': left of '::' must be a class/struct/union
C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\INCLUDE\vector(1892): error C2146: syntax error: missing '>' before identifier 'difference_type'
C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\INCLUDE\vector(1898): error C2825: '_Alloc': must be a class or namespace when followed by '::'
C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\INCLUDE\vector(1898): error C2510: '_Alloc': left of '::' must be a class/struct/union
C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\INCLUDE\vector(1898): error C3646: '_Sizet': unknown override specifier
C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\INCLUDE\vector(1898): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\INCLUDE\vector(1906): error C2061: syntax error: identifier '_Sizet'
C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\INCLUDE\vector(1913): error C2061: syntax error: identifier '_Sizet'
C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\INCLUDE\vector(1920): error C2061: syntax error: identifier '_Sizet'
C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\INCLUDE\vector(1937): error C3646: '_Myoff': unknown override specifier
C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\INCLUDE\vector(1937): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
And yes - i do know this is now the msvc2015 compiler! I tested this one too, and these are the error messages from this compile
Is this a weird bug in msvc or why does and can this even happen?

This is a known issue in MSVC compilers. They argue that "calling swap() with explicit template arguments is not actually permitted by the Standard".

Related

Visual Studio 2019 C++ and std::filesystem changing to ISO C++17 Standard or adding _HAS_CXX17 1 do not work

based on this thread it is still not working although i changed to ISO C++17 Standard (/std:c++17)
in c++ -> language in VS 2019 config.
also try to set :
#ifdef _WIN32
#define _HAS_CXX17 1
#endif
it worked but to day it gave me compilation error all over :
warning C4005: '_HAS_CXX17': macro redefinition
1>C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.28.29333\include\vcruntime.h(277): message : see previous definition of '_HAS_CXX17'
1>C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.28.29333\include\algorithm(315,10): error C2061: syntax error: identifier '_Enable_if_execution_policy_t'
1>C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.28.29333\include\algorithm(315,86): error C2988: unrecognizable template declaration/definition
1>C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.28.29333\include\algorithm(315,86): error C2059: syntax error: '='
1>C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.28.29333\include\algorithm(337,10): error C2061: syntax error: identifier '_Enable_if_execution_policy_t'
is there any solution to this ?

Visual Studio All c++ functions are not members of global namespace

I recently installed Visual studio as I'm working to pick up c++ more. However in c++, even running something as simple as a hello world code yields me a huge number of errors such as
1>C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.24.28314\include\cstdlib(24,18): error C2039: 'fabs': is not a member of 'global namespace'
1>C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.24.28314\include\cstdlib(24,22): error C3861: 'fabs': identifier not found
1>C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.24.28314\include\cstdlib(28,18): error C2039: 'fabsf': is not a member of 'global namespace'
1>C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.24.28314\include\cstdlib(28,23): error C3861: 'fabsf': identifier not found
1>C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.24.28314\include\cstdlib(32,18): error C2039: 'fabsl': is not a member of 'global namespace'
1>C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.24.28314\include\cstdlib(32,23): error C3861: 'fabsl': identifier not found
The error seems to be either an issue with my VS setup or my C++ Distribution. Is this a common issue? Has anyone else seen this before?
Here is the code
#include <iostream>
int main()
{
std::cout << "Hello World!\n";
return 0;
}

Visual studio 14.0 giving compile errors with cstdint and stdint.h

I'm trying to build a c++ program using the allegro library for school, but I can't seem to get past a massive list of compile errors dealing with cstdint and stdint.h
Removing all the code from my files gives me a header file with just this
#pragma once
#include <allegro.h>
#include <cstdlib>
#include <cstdio>
#include <sstream>
#include <fstream>
and my main file just containing
#include "Trivia.h"
and here are the errors I'm trying to deal with
1>c:\program files (x86)\microsoft visual studio 14.0\vc\include\stdint.h(17): warning C4114: same type qualifier used more than once
1>c:\program files (x86)\microsoft visual studio 14.0\vc\include\stdint.h(17): error C2632: 'char' followed by 'char' is illegal
1>c:\program files (x86)\microsoft visual studio 14.0\vc\include\stdint.h(17): warning C4091: 'typedef ': ignored on left of 'signed char' when no variable is declared
1>c:\program files (x86)\microsoft visual studio 14.0\vc\include\stdint.h(18): error C2632: 'short' followed by 'short' is illegal
1>c:\program files (x86)\microsoft visual studio 14.0\vc\include\stdint.h(18): warning C4091: 'typedef ': ignored on left of 'short' when no variable is declared
1>c:\program files (x86)\microsoft visual studio 14.0\vc\include\stdint.h(19): error C2632: 'int' followed by 'int' is illegal
1>c:\program files (x86)\microsoft visual studio 14.0\vc\include\stdint.h(19): warning C4091: 'typedef ': ignored on left of 'int' when no variable is declared
1>c:\program files (x86)\microsoft visual studio 14.0\vc\include\stdint.h(20): error C2632: '__int64' followed by '__int64' is illegal
1>c:\program files (x86)\microsoft visual studio 14.0\vc\include\stdint.h(20): warning C4091: 'typedef ': ignored on left of '__int64' when no variable is declared
1>c:\program files (x86)\microsoft visual studio 14.0\vc\include\stdint.h(21): warning C4114: same type qualifier used more than once
1>c:\program files (x86)\microsoft visual studio 14.0\vc\include\stdint.h(21): error C2632: 'char' followed by 'char' is illegal
1>c:\program files (x86)\microsoft visual studio 14.0\vc\include\stdint.h(21): warning C4091: 'typedef ': ignored on left of 'unsigned char' when no variable is declared
1>c:\program files (x86)\microsoft visual studio 14.0\vc\include\stdint.h(22): warning C4114: same type qualifier used more than once
1>c:\program files (x86)\microsoft visual studio 14.0\vc\include\stdint.h(22): error C2632: 'short' followed by 'short' is illegal
1>c:\program files (x86)\microsoft visual studio 14.0\vc\include\stdint.h(22): warning C4091: 'typedef ': ignored on left of 'unsigned short' when no variable is declared
1>c:\program files (x86)\microsoft visual studio 14.0\vc\include\stdint.h(23): warning C4114: same type qualifier used more than once
1>c:\program files (x86)\microsoft visual studio 14.0\vc\include\stdint.h(23): error C2632: 'int' followed by 'int' is illegal
1>c:\program files (x86)\microsoft visual studio 14.0\vc\include\stdint.h(23): warning C4091: 'typedef ': ignored on left of 'unsigned int' when no variable is declared
1>c:\program files (x86)\microsoft visual studio 14.0\vc\include\stdint.h(24): warning C4114: same type qualifier used more than once
1>c:\program files (x86)\microsoft visual studio 14.0\vc\include\stdint.h(24): error C2632: '__int64' followed by '__int64' is illegal
1>c:\program files (x86)\microsoft visual studio 14.0\vc\include\stdint.h(24): warning C4091: 'typedef ': ignored on left of 'unsigned __int64' when no variable is declared
1>c:\program files (x86)\microsoft visual studio 14.0\vc\include\cstdint(18): error C2589: 'signed': illegal token on right side of '::'
1>c:\program files (x86)\microsoft visual studio 14.0\vc\include\cstdint(18): error C2059: syntax error: '::'
1>c:\program files (x86)\microsoft visual studio 14.0\vc\include\cstdint(19): error C2589: 'signed': illegal token on right side of '::'
1>c:\program files (x86)\microsoft visual studio 14.0\vc\include\cstdint(19): error C2059: syntax error: '::'
1>c:\program files (x86)\microsoft visual studio 14.0\vc\include\cstdint(20): error C2589: 'unsigned': illegal token on right side of '::'
1>c:\program files (x86)\microsoft visual studio 14.0\vc\include\cstdint(20): error C2059: syntax error: '::'
1>c:\program files (x86)\microsoft visual studio 14.0\vc\include\cstdint(21): error C2589: 'unsigned': illegal token on right side of '::'
1>c:\program files (x86)\microsoft visual studio 14.0\vc\include\cstdint(21): error C2059: syntax error: '::'
1>c:\program files (x86)\microsoft visual studio 14.0\vc\include\cstdint(33): error C2589: 'signed': illegal token on right side of '::'
1>c:\program files (x86)\microsoft visual studio 14.0\vc\include\cstdint(33): error C2059: syntax error: '::'
1>c:\program files (x86)\microsoft visual studio 14.0\vc\include\cstdint(34): error C2589: 'unsigned': illegal token on right side of '::'
1>c:\program files (x86)\microsoft visual studio 14.0\vc\include\cstdint(34): error C2059: syntax error: '::'
1>c:\program files (x86)\microsoft visual studio 14.0\vc\include\cstdint(37): error C2589: 'signed': illegal token on right side of '::'
1>c:\program files (x86)\microsoft visual studio 14.0\vc\include\cstdint(37): error C2059: syntax error: '::'
1>c:\program files (x86)\microsoft visual studio 14.0\vc\include\cstdint(38): error C2589: 'signed': illegal token on right side of '::'
1>c:\program files (x86)\microsoft visual studio 14.0\vc\include\cstdint(38): error C2059: syntax error: '::'
1>c:\program files (x86)\microsoft visual studio 14.0\vc\include\cstdint(39): error C2589: 'unsigned': illegal token on right side of '::'
1>c:\program files (x86)\microsoft visual studio 14.0\vc\include\cstdint(39): error C2059: syntax error: '::'
1>c:\program files (x86)\microsoft visual studio 14.0\vc\include\cstdint(40): error C2589: 'unsigned': illegal token on right side of '::'
1>c:\program files (x86)\microsoft visual studio 14.0\vc\include\cstdint(40): error C2059: syntax error: '::'
1>c:\program files (x86)\microsoft visual studio 14.0\vc\include\cstdint(52): error C2589: 'signed': illegal token on right side of '::'
1>c:\program files (x86)\microsoft visual studio 14.0\vc\include\cstdint(52): error C2059: syntax error: '::'
1>c:\program files (x86)\microsoft visual studio 14.0\vc\include\cstdint(53): error C2589: 'unsigned': illegal token on right side of '::'
1>c:\program files (x86)\microsoft visual studio 14.0\vc\include\cstdint(53): error C2059: syntax error: '::'
I can get the errors to disappear if I remove all of stdio.h, sstream and fstream but I kinda need those for my assignment.
#include <stdlib.h>
#include <stdio.h>
they are C headers, you need C++ ones:
#include <cstdlib>
#include <cstdio>
EDIT:
First you have a bunch of errors from stdint.h (C header!), then from cstrint. Just a guess, but if allegro is a C library (not C++), you also need to change
#include <allegro.h>
to
extern "C"
{
#include <allegro.h>
}
Apparently I can solve the problem by including allegro.h after sstream and fstream. I don't know why this fixes the problem (and I've seen other code including allegro.h first) but at least it works.

errors occur when using cl cmd to generate dll file?

Today, I used cl cmd which is vs 2010 attached to compile a demo to gain a dll file. I written a file, its content as follow:
CALL "D:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\vcvarsall.bat" x86
cl /LD getKLineForKdb.cpp getKLineForKdb.def TDB_API_Windows_v2.lib q.lib
and saved it as comprun.bat. When I used cmd to run it, some error messages occurred:
d:\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 SDKs\Windows\v7.0A\include\wingdi.h(4562) : error C2143: syntax error : missing ',' before '->'
C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\include\wingdi.h(4563) : error C2143: syntax error : missing ',' before '->'
C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\include\mmsystem.h(770) : error C2059: syntax error : 'constant'
C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\include\mmsystem.h(770) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\include\mmsystem.h(770) : warning C4183: 'waveformat_tag': missing return type; assumed to be a member function returning 'int'.
Does anyone face this problem? Thanks.

Error linking source file with static library C++

I'm trying to use the static library however when I add the reference and include directories to the project I get strange compiler errors, this including only any header file.
The static library project builds successful. I don't know where the error may be, but I suppose it may be in some file of the static library.
The static library files are the following:
header:
#ifndef UTIL_H_
#define UTIL_H_
#include <string>
#include <iostream>
#include <vector>
#include <stdlib.h>
namespace Kaczmarz {
class Util {
public:
Util();
static void split(std::vector<std::string> &tokens, const std::string &text, char sep);
static double random(int rangeMin,int rangeMax);
virtual ~Util();
};
}
#endif
cpp:
#include "Util.h"
namespace Kaczmarz {
Util::Util() {
// TODO Auto-generated constructor stub
}
void Util::split(std::vector<std::string> &tokens, const std::string &text, char sep) {
unsigned int start = 0, end = 0;
while ((end = text.find(sep, start)) != std::string::npos) {
tokens.push_back(text.substr(start, end - start));
start = end + 1;
}
tokens.push_back(text.substr(start));
}
double Util::random(int rangeMin,int rangeMax){
return (double) static_cast<double>( rand() ) * rangeMax / static_cast<double>( RAND_MAX ) + rangeMin;
}
Util::~Util() {
// TODO Auto-generated destructor stub
}
}
the file that tries to use the static library:
#include <iostream>
using namespace std;
//using namespace Kaczmarz;
int main(){
cout << "Started.." << endl;
return 0;
}
Note that I'm not calling yet any function from the library.
The errors that I got are the following:
1>c:\program files (x86)\microsoft visual studio 11.0\vc\include\string(21): error C2143: syntax error : missing ';' before '<'
1>c:\program files (x86)\microsoft visual studio 11.0\vc\include\string(21): error C2433: 'basic_string' : 'inline' not permitted on data declarations
1>c:\program files (x86)\microsoft visual studio 11.0\vc\include\string(21): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\program files (x86)\microsoft visual studio 11.0\vc\include\string(21): error C2988: unrecognizable template declaration/definition
1>c:\program files (x86)\microsoft visual studio 11.0\vc\include\string(21): error C2059: syntax error : '<'
1>c:\program files (x86)\microsoft visual studio 11.0\vc\include\string(38): error C2143: syntax error : missing ';' before '{'
1>c:\program files (x86)\microsoft visual studio 11.0\vc\include\string(38): error C2447: '{' : missing function header (old-style formal list?)
1>c:\program files (x86)\microsoft visual studio 11.0\vc\include\string(49): error C2143: syntax error : missing ';' before '<'
1>c:\program files (x86)\microsoft visual studio 11.0\vc\include\string(49): error C2433: 'basic_string' : 'inline' not permitted on data declarations
1>c:\program files (x86)\microsoft visual studio 11.0\vc\include\string(49): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\program files (x86)\microsoft visual studio 11.0\vc\include\string(49): error C2086: 'int std::basic_string' : redefinition
1> c:\program files (x86)\microsoft visual studio 11.0\vc\include\string(21) : see declaration of 'std::basic_string'
1>c:\program files (x86)\microsoft visual studio 11.0\vc\include\string(49): error C2988: unrecognizable template declaration/definition
1>c:\program files (x86)\microsoft visual studio 11.0\vc\include\string(49): error C2059: syntax error : '<'
1>c:\program files (x86)\microsoft visual studio 11.0\vc\include\string(66): error C2143: syntax error : missing ';' before '{'
1>c:\program files (x86)\microsoft visual studio 11.0\vc\include\string(66): error C2447: '{' : missing function header (old-style formal list?)
1>c:\program files (x86)\microsoft visual studio 11.0\vc\include\string(77): error C2143: syntax error : missing ';' before '<'
1>c:\program files (x86)\microsoft visual studio 11.0\vc\include\string(77): error C2433: 'basic_string' : 'inline' not permitted on data declarations
1>c:\program files (x86)\microsoft visual studio 11.0\vc\include\string(77): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\program files (x86)\microsoft visual studio 11.0\vc\include\string(77): error C2086: 'int std::basic_string' : redefinition
1> c:\program files (x86)\microsoft visual studio 11.0\vc\include\string(21) : see declaration of 'std::basic_string'
1>c:\program files (x86)\microsoft visual studio 11.0\vc\include\string(77): error C2988: unrecognizable template declaration/definition
1>c:\program files (x86)\microsoft visual studio 11.0\vc\include\string(77): error C2059: syntax error : '<'
1>c:\program files (x86)\microsoft visual studio 11.0\vc\include\string(94): error C2143: syntax error : missing ';' before '{'
1>c:\program files (x86)\microsoft visual studio 11.0\vc\include\string(94): error C2447: '{' : missing function header (old-style formal list?)
1>c:\program files (x86)\microsoft visual studio 11.0\vc\include\string(101): error C2143: syntax error : missing ';' before '<'
1>c:\program files (x86)\microsoft visual studio 11.0\vc\include\string(101): error C2433: 'basic_string' : 'inline' not permitted on data declarations
1>c:\program files (x86)\microsoft visual studio 11.0\vc\include\string(101): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\program files (x86)\microsoft visual studio 11.0\vc\include\string(101): error C2086: 'int std::basic_string' : redefinition
1> c:\program files (x86)\microsoft visual studio 11.0\vc\include\string(21) : see declaration of 'std::basic_string'
1>c:\program files (x86)\microsoft visual studio 11.0\vc\include\string(101): error C2988: unrecognizable template declaration/definition
1>c:\program files (x86)\microsoft visual studio 11.0\vc\include\string(101): error C2059: syntax error : '<'
1>c:\program files (x86)\microsoft visual studio 11.0\vc\include\string(114): error C2143: syntax error : missing ';' before '{'
1>c:\program files (x86)\microsoft visual studio 11.0\vc\include\string(114): error C2447: '{' : missing function header (old-style formal list?)
1>c:\program files (x86)\microsoft visual studio 11.0\vc\include\string(125): error C2143: syntax error : missing ';' before '<'
1>c:\program files (x86)\microsoft visual studio 11.0\vc\include\string(125): error C2433: 'basic_string' : 'inline' not permitted on data declarations
1>c:\program files (x86)\microsoft visual studio 11.0\vc\include\string(125): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\program files (x86)\microsoft visual studio 11.0\vc\include\string(125): error C2086: 'int std::basic_string' : redefinition
1> c:\program files (x86)\microsoft visual studio 11.0\vc\include\string(21) : see declaration of 'std::basic_string'
1>c:\program files (x86)\microsoft visual studio 11.0\vc\include\string(125): error C2988: unrecognizable template declaration/definition
1>c:\program files (x86)\microsoft visual studio 11.0\vc\include\string(125): error C2059: syntax error : '<'
1>c:\program files (x86)\microsoft visual studio 11.0\vc\include\string(138): error C2143: syntax error : missing ';' before '{'
1>c:\program files (x86)\microsoft visual studio 11.0\vc\include\string(138): error C2447: '{' : missing function header (old-style formal list?)
1>c:\program files (x86)\microsoft visual studio 11.0\vc\include\string(145): error C2143: syntax error : missing ';' before '<'
1>c:\program files (x86)\microsoft visual studio 11.0\vc\include\string(145): error C2433: 'basic_string' : 'inline' not permitted on data declarations
1>c:\program files (x86)\microsoft visual studio 11.0\vc\include\string(145): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\program files (x86)\microsoft visual studio 11.0\vc\include\string(145): error C2086: 'int std::basic_string' : redefinition
1> c:\program files (x86)\microsoft visual studio 11.0\vc\include\string(21) : see declaration of 'std::basic_string'
1>c:\program files (x86)\microsoft visual studio 11.0\vc\include\string(145): error C2988: unrecognizable template declaration/definition
1>c:\program files (x86)\microsoft visual studio 11.0\vc\include\string(145): error C2059: syntax error : '<'
1>c:\program files (x86)\microsoft visual studio 11.0\vc\include\string(158): error C2143: syntax error : missing ';' before '{'
1>c:\program files (x86)\microsoft visual studio 11.0\vc\include\string(158): error C2447: '{' : missing function header (old-style formal list?)
1>c:\program files (x86)\microsoft visual studio 11.0\vc\include\string(166): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\program files (x86)\microsoft visual studio 11.0\vc\include\string(166): error C2143: syntax error : missing ',' before '<'
1>c:\program files (x86)\microsoft visual studio 11.0\vc\include\string(170): error C2803: 'operator ==' must have at least one formal parameter of class type
1>c:\program files (x86)\microsoft visual studio 11.0\vc\include\string(170): error C2805: binary 'operator ==' has too few parameters
1>c:\program files (x86)\microsoft visual studio 11.0\vc\include\string(177): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\program files (x86)\microsoft visual studio 11.0\vc\include\string(177): error C2143: syntax error : missing ',' before '<'
1>c:\program files (x86)\microsoft visual studio 11.0\vc\include\string(180): error C2803: 'operator ==' must have at least one formal parameter of class type
1>c:\program files (x86)\microsoft visual studio 11.0\vc\include\string(186): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\program files (x86)\microsoft visual studio 11.0\vc\include\string(186): error C2143: syntax error : missing ',' before '<'
1>c:\program files (x86)\microsoft visual studio 11.0\vc\include\string(190): fatal error C1903: unable to recover from previous error(s); stopping compilation
Note that the errors mention the std string class.
Since it's Christmas time and I see that you're using MSVS, here are steps that I did to try your library:
Step 1: I have created new solution called XmasTest with new Win32 project in it called XmasLib.
Step 2: I have added your source files in that project, just a simple example-appropriate modification. I have even let that evil using namespace std; line in the header file.
Util.h
#ifndef UTIL_H_
#define UTIL_H_
#include <string>
#include <iostream>
#include <vector>
#include <stdlib.h>
using namespace std;
namespace Kaczmarz {
class Util {
public:
Util();
static void print();
virtual ~Util();
};
} /* namespace Kaczmarz */
#endif
Util.cpp
#include "Util.h"
using namespace std;
namespace Kaczmarz {
Util::Util() {
// TODO Auto-generated constructor stub
}
void Util::print() {
cout << "Util::print() works! yay!" << endl;
}
Util::~Util() {
}
} /* namespace Kaczmarz */
Step 3: I have created new Win32 Console application called XmasLibTestApp with following code in it:
#include <iostream>
#include "../XmasLib/Util.h"
using namespace std;
using namespace Kaczmarz;
int main(){
Util u;
u.print();
return 0;
}
Step 4: Since these are 2 projects within 1 solution, I have handled the dependency in the following way:
Linker->General->Additional Library Directories: $(OutDir)
Linker->Input->Additional Dependencies: XmasLib.lib
Solution Properties->ProjectDependencies: App depends on lib
Step 5: Build Solution and run app. Output: Util::print() works! yay!
And that's it. End of the story, everything works, developer rejoices with his IDE.
Happy Xmas! :D
PS: Questions that are worth to have a look at:
Why is "using namespace std" considered bad practice?
What requires me to declare "using namespace std;"?
where to put using namespace std;
Ok found the cause of this compiling errors.
In the "additional include directories" (vs 2012) I had another .cpp/.h files which imported "Util" class.
I just removed this files from the directory and this time it compiled good without any errors. Note that this files weren't present in the project (I had excluded them), however seems that "additional include directories" linked them somehow in the project.
Thanks to all who have answered, I really appreciate it.