I have created a project inside Visual Studio with Visual Micro. Can't figure out this issue. I have this TestClass.h file
#pragma once
#include <map>
#include "Arduino.h"
class TestClass
{
private:
std::map<unsigned,unsigned> umm;
std::map<int,int> mmm;
public:
TestClass(void);
~TestClass(void);
};
This code gives the following errors:
> Compiling 'testPrj' for 'Arduino Uno' TestClass.cpp : In file included
> from TestClass.h : ISO C++ forbids declaration of 'map' with no type
> TestClass.h : ' TestClass.h : expected ';' before '<' token
> TestClass.h : ISO C++ forbids declaration of 'map' with no type
> TestClass.h : ' TestClass.h : expected ';' before '<' token Error
> compiling
What am I doing wrong?
The Arduino by default does not support the STL so you cannot use STL data structures.
As tzerb points out. There is an implementation of the STL for the AVR (Installation directions). I have not used it so I can't tell you if it is any good.
Related
I am trying to find EFI partition using CM_Get_Device_ID_ListW(), CM_Get_DevNode_PropertyW(), and ZwDeviceIoControlFile() Windows API. This is a shell application only. I used stdio to print on terminal. Below is the order of adding all header files. I tried to include following files:
#include <WINDOWS.h>
#include <initguid.h>
#include <devguid.h>
#include <devpkey.h>
#include <diskguid.h>
#include <stdio.h>
#include <cfgmgr32.h>
#include <Wdm.h>
I am using Windows 7, 64-bit, Visual Studio 2010. In VS2010 I set the include path:
F:\Programs\WINDDK\7600.16385.1\inc;F:\Programs\WINDDK\7600.16385.1\inc\api;F:\Programs\WINDDK\7600.16385.1\inc\crt;F:\Programs\WINDDK\7600.16385.1\inc\ddk;
Lib path:
F:\Programs\WINDDK\7600.16385.1\lib\win7\i386\
I get Compile Errors like:
f:\programs\winddk\7600.16385.1\inc\api\ntdef.h(128): warning C4005: 'MAX_NATURAL_ALIGNMENT' : macro redefinition
f:\programs\winddk\7600.16385.1\inc\api\winnt.h(109) : see previous definition of 'MAX_NATURAL_ALIGNMENT'
f:\programs\winddk\7600.16385.1\inc\api\ntdef.h(161): warning C4005: 'PROBE_ALIGNMENT' : macro redefinition
f:\programs\winddk\7600.16385.1\inc\api\winnt.h(142) : see previous definition of 'PROBE_ALIGNMENT'
f:\programs\winddk\7600.16385.1\inc\api\ntdef.h(614): error C2011: '_PROCESSOR_NUMBER' : 'struct' type redefinition
f:\programs\winddk\7600.16385.1\inc\api\winnt.h(493) : see declaration of '_PROCESSOR_NUMBER'
f:\programs\winddk\7600.16385.1\inc\api\ntdef.h(625): error C2011: '_GROUP_AFFINITY' : 'struct' type redefinition
f:\programs\winddk\7600.16385.1\inc\api\winnt.h(504) : see declaration of '_GROUP_AFFINITY'
f:\programs\winddk\7600.16385.1\inc\api\ntdef.h(882): error C2011: '_FLOAT128' : 'struct' type redefinition
f:\programs\winddk\7600.16385.1\inc\api\winnt.h(630) : see declaration of '_FLOAT128'
f:\programs\winddk\7600.16385.1\inc\api\ntdef.h(933): error C2011: '_LARGE_INTEGER' : 'union' type redefinition
f:\programs\winddk\7600.16385.1\inc\api\winnt.h(677) : see declaration of '_LARGE_INTEGER'
f:\programs\winddk\7600.16385.1\inc\api\ntdef.h(951): error C2011: '_ULARGE_INTEGER' : 'union' type redefinition
f:\programs\winddk\7600.16385.1\inc\api\winnt.h(695) : see declaration of '_ULARGE_INTEGER'
f:\programs\winddk\7600.16385.1\inc\api\ntdef.h(973): error C2011: '_LUID' : 'struct' type redefinition
f:\programs\winddk\7600.16385.1\inc\api\winnt.h(717) : see declaration of '_LUID'
f:\programs\winddk\7600.16385.1\inc\api\ntdef.h(1070): error C2084: function 'ULONGLONG Int64ShllMod32(ULONGLONG,DWORD)' already has a body
f:\programs\winddk\7600.16385.1\inc\api\winnt.h(771) : see previous definition of 'Int64ShllMod32'
f:\programs\winddk\7600.16385.1\inc\api\ntdef.h(1086): error C2084: function 'LONGLONG Int64ShraMod32(LONGLONG,DWORD)' already has a body
f:\programs\winddk\7600.16385.1\inc\api\winnt.h(778) : see previous definition of 'Int64ShraMod32'
f:\programs\winddk\7600.16385.1\inc\api\ntdef.h(1102): error C2084: function 'ULONGLONG Int64ShrlMod32(ULONGLONG,DWORD)' already has a body
f:\programs\winddk\7600.16385.1\inc\api\winnt.h(785) : see previous definition of 'Int64ShrlMod32'
f:\programs\winddk\7600.16385.1\inc\api\ntdef.h(1318): warning C4005: 'UNICODE_STRING_MAX_BYTES' : macro redefinition
f:\programs\winddk\7600.16385.1\inc\api\winnt.h(957) : see previous definition of 'UNICODE_STRING_MAX_BYTES'
f:\programs\winddk\7600.16385.1\inc\api\ntdef.h(1358): error C2011: '_LIST_ENTRY' : 'struct' type redefinition
f:\programs\winddk\7600.16385.1\inc\api\winnt.h(966) : see declaration of '_LIST_ENTRY'....
Can anyone help to resolve this?
I want to define the following alias into the namespace Library:
namespace Library
{
template <typename T>
using MyVector = std::vector<T, std::allocator<T> >;
}
but I get the following error from the compiler:
expected unqualified-id before 'using'
I'm following the official reference on cppreference.com but so far I couldn't make it work. What am I missing?
Some programmer dude got it: C++11 was not set.
To set the proper dialect go to: Project->Properties->C/C++ Build->Settings->Tool Settings->GCC C++ Compiler->Dialect->Language Standard->ISO C++ 11
I use Visual Studio 9 (2008).
When I compile this simple program:
#include <boost/log/trivial.hpp>
int main(int /*argc*/, char** /*argv*/)
{
BOOST_LOG_TRIVIAL(info) << "padaka";
}
I get a warning:
..\..\deps\boost_1_55_0\boost/parameter/aux_/tagged_argument.hpp(123) : warning C4100: 'x' : unreferenced formal parameter
..\..\deps\boost_1_55_0\boost/log/sources/severity_feature.hpp(252) : see reference to function template instantiation 'const boost::log::v2s_mt_nt5::trivial::severity_level &boost::parameter::aux::tagged_argument<Keyword,Arg>::operator []<boost::log::v2s_mt_nt5::trivial::severity_level>(const boost::parameter::aux::default_<Keyword,Value> &) const' being compiled
with
[
Keyword=boost::log::v2s_mt_nt5::keywords::tag::severity,
Arg=const boost::log::v2s_mt_nt5::trivial::severity_level,
Value=boost::log::v2s_mt_nt5::trivial::severity_level
]
..\..\deps\boost_1_55_0\boost/log/sources/basic_logger.hpp(459) : see reference to function template instantiation 'boost::log::v2s_mt_nt5::record boost::log::v2s_mt_nt5::sources::basic_severity_logger<BaseT,LevelT>::open_record_unlocked<ArgsT>(const ArgsT &)' being compiled
with
[
BaseT=boost::log::v2s_mt_nt5::sources::basic_logger<char,boost::log::v2s_mt_nt5::sources::severity_logger_mt<boost::log::v2s_mt_nt5::trivial::severity_level>,boost::log::v2s_mt_nt5::sources::multi_thread_model<boost::log::v2s_mt_nt5::aux::light_rw_mutex>>,
LevelT=boost::log::v2s_mt_nt5::trivial::severity_level,
ArgsT=boost::parameter::aux::tagged_argument<boost::log::v2s_mt_nt5::keywords::tag::severity,const boost::log::v2s_mt_nt5::trivial::severity_level>
]
..\..\src\MRCPClient\main.cpp(5) : see reference to function template instantiation 'boost::log::v2s_mt_nt5::record boost::log::v2s_mt_nt5::sources::basic_composite_logger<CharT,FinalT,ThreadingModelT,FeaturesT>::open_record<boost::parameter::aux::tagged_argument<Keyword,Arg>>(const ArgsT &)' being compiled
with
[
CharT=char,
FinalT=boost::log::v2s_mt_nt5::sources::severity_logger_mt<boost::log::v2s_mt_nt5::trivial::severity_level>,
ThreadingModelT=boost::log::v2s_mt_nt5::sources::multi_thread_model<boost::log::v2s_mt_nt5::aux::light_rw_mutex>,
FeaturesT=boost::log::v2s_mt_nt5::sources::features<boost::log::v2s_mt_nt5::sources::severity<boost::log::v2s_mt_nt5::trivial::severity_level>>,
Keyword=boost::log::v2s_mt_nt5::keywords::tag::severity,
Arg=const boost::log::v2s_mt_nt5::trivial::severity_level,
ArgsT=boost::parameter::aux::tagged_argument<boost::log::v2s_mt_nt5::keywords::tag::severity,const boost::log::v2s_mt_nt5::trivial::severity_level>
]
Program works correctly, but this is really annoying when you log a lot.
Any ideas how to solve it?
It just means that a parameter is not being used.
Sadly since the warning is generated from within Boost sources, and more notably inside class templates, my experience is that the only way to silence the warning is to disable it globally (e.g. using a pragma or a compiler option):
#pragma warning(push)
#pragma warning(disable: 4100)
#include <boost/log/trivial.hpp>
#pragma warning(pop)
My experience is that you cannot properly restore the warning (likely because of template Point-Of-Instantiations), so you may end up having to use:
#pragma warning(disable: 4100)
#include <boost/log/trivial.hpp>
See also:
Is using #pragma warning push/pop the right way to temporarily alter warning level? and (many) others
I am working on a project where I have to support IPv6 addressing scheme. This requires me to replace winsock.h with winsock2.h to make IP-version independent calls. Initially, I faced redefinition related errors which I could remove by employing solutions available online (placing #include <winsock2.h> before #include <windows.h>; including #define_WINSOCKAPI_). However, I am still getting errors like:
2>../include\obsocket.h(171) : error C2143: syntax error : missing '}' before 'constant'
2>../include\obsocket.h(171) : error C2059: syntax error : 'constant'
2>../include\obsocket.h(171) : error C2143: syntax error : missing ';' before '}'
2>../include\obsocket.h(171) : error C2238: unexpected token(s) preceding ';'
2>../include\obsocket.h(173) : error C2065: 'ShutdownType' : undeclared identifier
2>../include\obsocket.h(177) : error C2146: syntax error : missing ';' before identifier 'GetDescriptor'
2>../include\obsocket.h(177) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
2>../include\obsocket.h(177) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
2>../include\obsocket.h(177) : error C2065: '_sock' : undeclared identifier
2>../include\obsocket.h(179) : error C2065: '_timeout' : undeclared identifier
2>../include\obsocket.h(180) : error C2065: '_use_blocking_calls' : undeclared identifier
2>../include\obsocket.h(181) : error C2065: '_req_pending' : undeclared identifier
2>../include\obsocket.h(185) : error C2270: 'ToString' : modifiers not allowed on nonmember functions
2>../include\obsocket.h(187) : error C2059: syntax error : 'private'
2>../include\obsocket.h(189) : error C2146: syntax error : missing ';' before identifier '_sock'
2>../include\obsocket.h(189) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
2>../include\obsocket.h(189) : error C2086: 'int SOCK_TYPE' : redefinition
2>../include\obsocket.h(177) : see declaration of 'SOCK_TYPE'
2>../include\obsocket.h(189) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
2>../include\obsocket.h(189) : error C2371: '_sock' : redefinition; different basic types
2>../include\obsocket.h(199) : error C2371: '_use_blocking_calls' : redefinition; different basic types
2>../include\obsocket.h(200) : error C2371: '_timeout' : redefinition; different basic types
2>../include\obsocket.h(201) : error C2371: '_req_pending' : redefinition; different basic types
2>../include\obsocket.h(203) : error C2146: syntax error : missing ')' before identifier 'sock'
2>../include\obsocket.h(203) : error C2146: syntax error : missing ';' before identifier 'sock'
2>../include\obsocket.h(203) : error C2371: 'SOCK_TYPE' : redefinition; different basic types
I've made sure that winsock.h is not getting included anywhere during the build (by enabling show includes during the build).
Here is the code for obsocket.h:
#ifndef _obsocket_h
#define _obsocket_h
#ifdef _WIN32
#include <winsock2.h>
#include <ws2tcpip.h>
//#include <winsock.h>
#else
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#endif
class ObSocket {
public:
#ifdef _WIN32
typedef SOCKET SOCK_TYPE;
#else
typedef int SOCK_TYPE;
#endif
ObSocket();
~ObSocket();
enum ShutdownType { SD_INCOMING = 0, SD_OUTGOING = 1, SD_BOTH = 2 };
ObStatus Shutdown(ShutdownType);
ObStatus Close();
bool IsValid();
SOCK_TYPE GetDescriptor() { return _sock; }
void NonBlocking(int timeout);
inline int GetTimeout( ) { return _timeout; }
inline bool IsBlocking( ) { return _use_blocking_calls; }
inline int IncPendingReq(int i = 1) { _req_pending += i; return _req_pending; }
inline int DecPendingReq(int i = 1) { _req_pending -= i; return _req_pending; }
inline int GetPendingReq( ) { return _req_pending; }
ObString& ToString(ObString& strClass) const;
private:
SOCK_TYPE _sock;
ObInetAddress _addr;
char _my_addr[20];
in_port_t _my_port;
char _remote_addr[20];
in_port_t _remote_port;
bool _use_blocking_calls;
int _timeout;
int _req_pending;
ObSocket(SOCK_TYPE sock);
void SetAddr(sockaddr_in& inAddr, const ObInetAddress& addr, in_port_t port);
void ReallocFileDescriptor();
ObSocket(const ObSocket&);
ObSocket& operator=(const ObSocket&);
static void Initialize();
static void Finalize();
};
Can anyone help in pointing out what could be going wrong?
I am working on an application(contains 3 projects, 2 in c++ and one in Objective-C) which compiles perfectly for LLVM GCC compiler. But when I switch the compiler to 'Apple LLVM compiler 3.0' I found one strange error as follow:
error: implicit instantiation of undefined template 'EList<ETemplateString<char>>'
and above error shows in the following line of code:
EList<EString> outlist;
with the forward declared EList as follows:
template <class T> class EList; // forward decls
EString is declared as follow:
typedef ETemplateString<TCHAR> EString;
and rest of the used templates are defined as:
template <class T> class ETemplateString
{
//
//
//
}
and TCHAR is declared as:
typedef char TCHAR;
can anybody please let me know why it's compiling good with GCC and throwing errors in 'Apple LLVM compiler 3.0'
See http://clang.llvm.org/compatibility.html#undep_incomplete .