I'm using a pre-build 1.66 (lib32-msvc-14.0) that I've downloaded. I'm using Visual studio 2015.
I could run a sample without problem.
But in my project as soon as I include it( a simle wrapper), it generates a lot of errors.
here's my simple wrapper:
Net.h :
#ifndef _PCNET_h
#define _PCNET_h
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <boost/asio.hpp>
#include <string>
using boost::asio::ip::tcp;
typedef unsigned char byte;
typedef void(*newDataCallbackPtr)(byte cmd, byte *data, int len);
namespace net {
void init(std::string host, std::string port);
void send(byte cmd, byte *data, int len);
void registerCB(newDataCallbackPtr cb);
void join();
}
#endif
Net.cpp :
#include "Net.h"
const int max_length = 66000;
tcp::socket *s;
std::string delim = ";z|";
std::string recvData;
std::thread *t, *t2;
newDataCallbackPtr CB;
void readThrd();
//Public
void net::init(std::string host, std::string port) {
boost::asio::io_context io_context;
s = new tcp::socket(io_context);
tcp::resolver resolver(io_context);
boost::asio::connect(*s, resolver.resolve(host, port));
t = new std::thread([&io_context]() { io_context.run(); });
t2 = new std::thread(readThrd);
}
void net::send(byte cmd, byte *data, int len) {
byte *buff = new byte[len + 4];
buff[0] = cmd;
memcpy(buff + 1, data, len);
buff[len + 1] = ';';
buff[len + 2] = 'z';
buff[len + 3] = '|';
boost::asio::write(*s, boost::asio::buffer(buff, len + 4));
delete[] buff;
}
void net::registerCB(newDataCallbackPtr cb) {
CB = cb;
}
void net::join() {
t->join();
}
//Prv8
void readThrd() {
while (true)
{
size_t n = boost::asio::read_until(*s, boost::asio::dynamic_buffer(recvData), delim);
byte *buff = new byte[n - 3];
memcpy(buff, recvData.c_str(), n - 3);
recvData.erase(0, n);
CB(buff[0], buff + 1, (int)n - 4);
}
}
the rest of my project compiles without any problem. but as soon as i Include this Net.h (in another .cpp), compilers gives me a lot of errors in winuser and asio headers:
1>------ Build started: Project: pcMode, Configuration: Debug Win32 ------
1> PCutil.cpp
1> Please define _WIN32_WINNT or _WIN32_WINDOWS appropriately. For example:
1> - add -D_WIN32_WINNT=0x0501 to the compiler command line; or
1> - add _WIN32_WINNT=0x0501 to your project's Preprocessor Definitions.
1> Assuming _WIN32_WINNT=0x0501 (i.e. Windows XP target).
1>c:\program files (x86)\windows kits\8.1\include\um\winuser.h(5836): warning C4091: 'typedef ': ignored on left of 'tagINPUT' when no variable is declared
1>c:\program files (x86)\windows kits\8.1\include\um\winuser.h(5836): error C2143: syntax error: missing ';' before 'constant'
1>c:\program files (x86)\windows kits\8.1\include\um\winuser.h(5836): error C2059: syntax error: 'constant'
1>c:\program files (x86)\windows kits\8.1\include\um\winuser.h(5843): error C2061: syntax error: identifier 'LPINPUT'
1>c:\boost\boost_1_66_0\boost\asio\bind_executor.hpp(74): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\boost\boost_1_66_0\boost\asio\bind_executor.hpp(74): error C2059: syntax error: 'constant'
1>c:\boost\boost_1_66_0\boost\asio\bind_executor.hpp(75): error C2059: syntax error: ')'
1>c:\boost\boost_1_66_0\boost\asio\bind_executor.hpp(76): error C2976: 'boost::asio::detail::executor_binder_result_type': too few template arguments
1> c:\boost\boost_1_66_0\boost\asio\bind_executor.hpp(44): note: see declaration of 'boost::asio::detail::executor_binder_result_type'
1>c:\boost\boost_1_66_0\boost\asio\bind_executor.hpp(76): error C2143: syntax error: missing ';' before '{'
1>c:\boost\boost_1_66_0\boost\asio\bind_executor.hpp(76): error C2447: '{': missing function header (old-style formal list?)
1>c:\boost\boost_1_66_0\boost\asio\bind_executor.hpp(82): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\boost\boost_1_66_0\boost\asio\bind_executor.hpp(82): error C2059: syntax error: 'constant'
1>c:\boost\boost_1_66_0\boost\asio\bind_executor.hpp(83): error C2059: syntax error: ')'
1>c:\boost\boost_1_66_0\boost\asio\bind_executor.hpp(84): error C2976: 'boost::asio::detail::executor_binder_result_type': too few template arguments
1> c:\boost\boost_1_66_0\boost\asio\bind_executor.hpp(44): note: see declaration of 'boost::asio::detail::executor_binder_result_type'
1>c:\boost\boost_1_66_0\boost\asio\bind_executor.hpp(84): error C2143: syntax error: missing ';' before '{'
1>c:\boost\boost_1_66_0\boost\asio\bind_executor.hpp(84): error C2447: '{': missing function header (old-style formal list?)
1>c:\boost\boost_1_66_0\boost\asio\bind_executor.hpp(90): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\boost\boost_1_66_0\boost\asio\bind_executor.hpp(90): error C2059: syntax error: 'constant'
1>c:\boost\boost_1_66_0\boost\asio\bind_executor.hpp(91): error C2059: syntax error: ')'
1>c:\boost\boost_1_66_0\boost\asio\bind_executor.hpp(92): error C2974: 'boost::asio::detail::executor_binder_result_type': invalid template argument for 'T', type expected
1> c:\boost\boost_1_66_0\boost\asio\bind_executor.hpp(44): note: see declaration of 'boost::asio::detail::executor_binder_result_type'
1>c:\boost\boost_1_66_0\boost\asio\bind_executor.hpp(92): error C2143: syntax error: missing ';' before '{'
1>c:\boost\boost_1_66_0\boost\asio\bind_executor.hpp(92): error C2447: '{': missing function header (old-style formal list?)
1>c:\boost\boost_1_66_0\boost\asio\bind_executor.hpp(98): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\boost\boost_1_66_0\boost\asio\bind_executor.hpp(98): error C2059: syntax error: 'constant'
1>c:\boost\boost_1_66_0\boost\asio\bind_executor.hpp(99): error C2059: syntax error: ')'
1>c:\boost\boost_1_66_0\boost\asio\bind_executor.hpp(100): error C2974: 'boost::asio::detail::executor_binder_result_type': invalid template argument for 'T', type expected
1> c:\boost\boost_1_66_0\boost\asio\bind_executor.hpp(44): note: see declaration of 'boost::asio::detail::executor_binder_result_type'
1>c:\boost\boost_1_66_0\boost\asio\bind_executor.hpp(100): error C2143: syntax error: missing ';' before '{'
1>c:\boost\boost_1_66_0\boost\asio\bind_executor.hpp(100): error C2447: '{': missing function header (old-style formal list?)
1>c:\boost\boost_1_66_0\boost\asio\bind_executor.hpp(109): warning C4544: '<unnamed-symbol>': default template argument ignored on this template declaration
1> c:\boost\boost_1_66_0\boost\asio\bind_executor.hpp(108): note: see declaration of '<unnamed-symbol>'
1>c:\boost\boost_1_66_0\boost\asio\bind_executor.hpp(118): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\boost\boost_1_66_0\boost\asio\bind_executor.hpp(118): error C2059: syntax error: 'constant'
1>c:\boost\boost_1_66_0\boost\asio\bind_executor.hpp(119): error C2059: syntax error: ')'
1>c:\boost\boost_1_66_0\boost\asio\bind_executor.hpp(120): error C2976: 'boost::asio::detail::executor_binder_argument_type': too few template arguments
1> c:\boost\boost_1_66_0\boost\asio\bind_executor.hpp(109): note: see declaration of 'boost::asio::detail::executor_binder_argument_type'
1>c:\boost\boost_1_66_0\boost\asio\bind_executor.hpp(120): error C2143: syntax error: missing ';' before '{'
1>c:\boost\boost_1_66_0\boost\asio\bind_executor.hpp(120): error C2447: '{': missing function header (old-style formal list?)
1>c:\boost\boost_1_66_0\boost\asio\bind_executor.hpp(124): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\boost\boost_1_66_0\boost\asio\bind_executor.hpp(124): error C2059: syntax error: 'constant'
1>c:\boost\boost_1_66_0\boost\asio\bind_executor.hpp(125): error C2059: syntax error: ')'
1>c:\boost\boost_1_66_0\boost\asio\bind_executor.hpp(126): error C2976: 'boost::asio::detail::executor_binder_argument_type': too few template arguments
1> c:\boost\boost_1_66_0\boost\asio\bind_executor.hpp(109): note: see declaration of 'boost::asio::detail::executor_binder_argument_type'
1>c:\boost\boost_1_66_0\boost\asio\bind_executor.hpp(126): error C2143: syntax error: missing ';' before '{'
1>c:\boost\boost_1_66_0\boost\asio\bind_executor.hpp(126): error C2447: '{': missing function header (old-style formal list?)
1>c:\boost\boost_1_66_0\boost\asio\bind_executor.hpp(134): warning C4544: '<unnamed-symbol>': default template argument ignored on this template declaration
1> c:\boost\boost_1_66_0\boost\asio\bind_executor.hpp(133): note: see declaration of '<unnamed-symbol>'
1>c:\boost\boost_1_66_0\boost\asio\bind_executor.hpp(144): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\boost\boost_1_66_0\boost\asio\bind_executor.hpp(144): error C2059: syntax error: 'constant'
1>c:\boost\boost_1_66_0\boost\asio\bind_executor.hpp(145): error C2059: syntax error: ')'
1>c:\boost\boost_1_66_0\boost\asio\bind_executor.hpp(146): error C2976: 'boost::asio::detail::executor_binder_argument_type': too few template arguments
1> c:\boost\boost_1_66_0\boost\asio\bind_executor.hpp(109): note: see declaration of 'boost::asio::detail::executor_binder_argument_type'
1>c:\boost\boost_1_66_0\boost\asio\bind_executor.hpp(146): error C2143: syntax error: missing ';' before '{'
1>c:\boost\boost_1_66_0\boost\asio\bind_executor.hpp(146): error C2447: '{': missing function header (old-style formal list?)
1>c:\boost\boost_1_66_0\boost\asio\bind_executor.hpp(151): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\boost\boost_1_66_0\boost\asio\bind_executor.hpp(151): error C2059: syntax error: 'constant'
1>c:\boost\boost_1_66_0\boost\asio\bind_executor.hpp(152): error C2059: syntax error: ')'
1>c:\boost\boost_1_66_0\boost\asio\bind_executor.hpp(153): error C2976: 'boost::asio::detail::executor_binder_argument_type': too few template arguments
1> c:\boost\boost_1_66_0\boost\asio\bind_executor.hpp(109): note: see declaration of 'boost::asio::detail::executor_binder_argument_type'
1>c:\boost\boost_1_66_0\boost\asio\bind_executor.hpp(153): error C2143: syntax error: missing ';' before '{'
1>c:\boost\boost_1_66_0\boost\asio\bind_executor.hpp(153): error C2447: '{': missing function header (old-style formal list?)
1>c:\boost\boost_1_66_0\boost\asio\bind_executor.hpp(219): error C2976: 'boost::asio::detail::executor_binder_argument_type': too few template arguments
1> c:\boost\boost_1_66_0\boost\asio\bind_executor.hpp(109): note: see declaration of 'boost::asio::detail::executor_binder_argument_type'
1> c:\boost\boost_1_66_0\boost\asio\bind_executor.hpp(493): note: see reference to class template instantiation 'boost::asio::executor_binder<T,Executor>' being compiled
1>c:\boost\boost_1_66_0\boost\asio\bind_executor.hpp(219): error C2955: 'boost::asio::detail::executor_binder_argument_type': use of class template requires template argument list
1> c:\boost\boost_1_66_0\boost\asio\bind_executor.hpp(109): note: see declaration of 'boost::asio::detail::executor_binder_argument_type'
1>c:\boost\boost_1_66_0\boost\asio\bind_executor.hpp(220): error C2976: 'boost::asio::detail::executor_binder_argument_types': too few template arguments
1> c:\boost\boost_1_66_0\boost\asio\bind_executor.hpp(134): note: see declaration of 'boost::asio::detail::executor_binder_argument_types'
1>c:\boost\boost_1_66_0\boost\asio\bind_executor.hpp(220): error C2955: 'boost::asio::detail::executor_binder_argument_types': use of class template requires template argument list
1> c:\boost\boost_1_66_0\boost\asio\bind_executor.hpp(134): note: see declaration of 'boost::asio::detail::executor_binder_argument_types'
1> Net.cpp
1> Please define _WIN32_WINNT or _WIN32_WINDOWS appropriately. For example:
1> - add -D_WIN32_WINNT=0x0501 to the compiler command line; or
1> - add _WIN32_WINNT=0x0501 to your project's Preprocessor Definitions.
1> Assuming _WIN32_WINNT=0x0501 (i.e. Windows XP target).
1> Generating Code...
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
as for PCutil. it has a lot of codes, I've removed irrelevant parts. here's the related parts:
PCutil.h:
#ifndef _PCUTIL_h
#define _PCUTIL_h
#include <iostream>
#include <chrono>
#include <thread>
#include <queue>
#include <stdarg.h>
#include "pinNameDef.h"
extern int ardDigitalPin2PinNum[];
#define HIGH 1
#define OUTPUT 1
#define LOW 0
#define INPUT 0
typedef unsigned char byte;
extern byte exE2PR[];
extern byte inE2PR[];
void PCSend(NETCMDS id, int len, byte b1 = 0, byte b2 = 0, byte b3 = 0, byte b4 = 0, byte b5 = 0, byte b6 = 0, byte b7 = 0, byte b8 = 0);
void PCSend(NETCMDS id, int len, byte *data);
void init(char* host, char* port);
void joinNet();
#endif
PCutil.cpp
#include "PCutil.h"
#include "pinNameDef.h"
#include "../spec.h"
#include "../config.h"
#include "Net.h"
byte exE2PR[PCE2PRSIZE];
byte inE2PR[PCE2PRSIZE];
void PCSend(NETCMDS id, int len, byte b1, byte b2, byte b3, byte b4, byte b5, byte b6, byte b7, byte b8) {
byte b[] = { b1,b2,b3,b4,b5,b6,b7,b8 };
net::send(id, b, len + 1);
}
void PCSend(NETCMDS id, int len, byte *data) {
net::send(id, data, len);
}
void netCB(byte cmd, byte *data, int len) {
//some codes
}
void init(char* host, char* port) {
Net init
net::registerCB(netCB);
net::init(host, port);
}
void joinNet() {
net::join();
}
any idea whats wrong here?
Thanks.
Related
I try to measure the runtime of the program using Intel Pin. For this purpose I include chrono in my project. However It is not going to compile well. It gives a lot of errors. Furthermore, I tried to include chrono to many standart Intel Pin examples - the same result.
Could you please help me to solve errors below?
ratio(24,32): error C2143: syntax error: missing ',' before '<'
ratio(25): message : see reference to class template instantiation 'std::_Abs<_Val>' being compiled
ratio(30,38): error C2143: syntax error: missing ',' before '<'
ratio(31): message : see reference to class template instantiation 'std::_Safe_mult<_Ax,_Bx,_Sfinae,_Good>' being compiled
ratio(40,36): error C2143: syntax error: missing ',' before '<'
ratio(41): message : see reference to class template instantiation 'std::_Sign_of<_Val>' being compiled
ratio(45,38): error C2143: syntax error: missing ',' before '<'
ratio(46): message : see reference to class template instantiation 'std::_Safe_addX<_Ax,_Bx,_Good,_Also_good>' being compiled
ratio(50,44): error C2760: syntax error: unexpected token ',', expected 'expression'
ratio(51): message : see reference to class template instantiation 'std::_Safe_addX<_Ax,_Bx,false,false>' being compiled
ratio(65,41): error C2143: syntax error: missing ',' before '<'
ratio(66): message : see reference to class template instantiation 'std::_GcdX<_Ax,0>' being compiled
ratio(74,2): error C2504: 'integral_constant': base class undefined
ratio(74,38): error C2143: syntax error: missing ',' before '<'
ratio(158,5): error C2065: 'void_t': undeclared identifier
ratio(158,1): error C2226: syntax error: unexpected type 'std::_Ratio_multiply<_R1,_R2>::_Num::type'
ratio(159,1): error C2988: unrecognizable template declaration/definition
ratio(159,1): error C2059: syntax error: '>'
ratio(159,58): error C2143: syntax error: missing ';' before '{'
ratio(159,58): error C2447: '{': missing function header (old-style formal list?)
ratio(186,35): error C2143: syntax error: missing ',' before '<'
ratio(188): message : see reference to class template instantiation 'std::ratio_equal<_R1,_R2>' being compiled
ratio(195,39): error C2143: syntax error: missing ',' before '<'
ratio(197): message : see reference to class template instantiation 'std::ratio_not_equal<_R1,_R2>' being compiled
ratio(252,34): error C2143: syntax error: missing ',' before '<'
ratio(254): message : see reference to class template instantiation 'std::ratio_less<_R1,_R2>' being compiled
ratio(261,40): error C2143: syntax error: missing ',' before '<'
ratio(263): message : see reference to class template instantiation 'std::ratio_less_equal<_R1,_R2>' being compiled
ratio(279,43): error C2143: syntax error: missing ',' before '<'
ratio(282): message : see reference to class template instantiation 'std::ratio_greater_equal<_R1,_R2>' being compiled
1>C:\Program Files (x86)\Windows Kits\10\Include\10.0.18362.0\ucrt\corecrt.h(512,39): error C2371: 'wint_t': redefinition; different basic types
1>E:\Tools\source\pin\extras\crt\include\wchar.h(52): message : see declaration of 'wint_t'
1>C:\Program Files (x86)\Windows Kits\10\Include\10.0.18362.0\ucrt\corecrt.h(513,39): error C2371: 'wctype_t': redefinition; different basic types
1>E:\Tools\source\pin\extras\crt\include\wchar.h(77): message : see declaration of 'wctype_t'
1>C:\Program Files (x86)\Windows Kits\10\Include\10.0.18362.0\ucrt\corecrt.h(538,19): error C2371: 'mbstate_t': redefinition; different basic types
1>E:\Tools\source\pin\extras\crt\include\wchar.h(58): message : see declaration of 'mbstate_t'
1>C:\Program Files (x86)\Windows Kits\10\Include\10.0.18362.0\ucrt\corecrt.h(552,28): error C2371: 'time_t': redefinition; different basic types
1>E:\Tools\source\pin\extras\crt\include\sys\types.h(91): message : see declaration of 'time_t'
vcruntime_new.h(34,26): error C2011: 'std::nothrow_t': 'struct' type redefinition
1>E:\Tools\source\pin\extras\libstdc++\include\new(10): message : see declaration of 'std::nothrow_t'
vcruntime_new.h(168,5): error C2084: function 'void *operator new(size_t,void *)' already has a body
1>E:\Tools\source\pin\extras\libstdc++\include\new(36): message : see previous definition of 'new'
vcruntime_new.h(174,5): error C2084: function 'void operator delete(void *,void *) throw()' already has a body
1>E:\Tools\source\pin\extras\libstdc++\include\new(40): message : see previous definition of 'delete'
vcruntime_new.h(184,5): error C2084: function 'void *operator new[](size_t,void *)' already has a body
1>E:\Tools\source\pin\extras\libstdc++\include\new(37): message : see previous definition of 'new[]'
vcruntime_new.h(190,5): error C2084: function 'void operator delete[](void *,void *) throw()' already has a body
1>E:\Tools\source\pin\extras\libstdc++\include\new(41): message : see previous definition of 'delete[]'
xtimec.h(28,15): error C2144: syntax error: 'int' should be preceded by ';'
xtimec.h(28,19): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
xtimec.h(30,15): error C2144: syntax error: 'long' should be preceded by ';'
xtimec.h(30,20): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
xtimec.h(30,1): error C2086: 'int _CRTIMP2': redefinition
xtimec.h(28): message : see declaration of '_CRTIMP2'
xtimec.h(31,15): error C2144: syntax error: 'long' should be preceded by ';'
xtimec.h(31,20): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
xtimec.h(31,1): error C2086: 'int _CRTIMP2': redefinition
xtimec.h(28): message : see declaration of '_CRTIMP2'
xtimec.h(32,15): error C2144: syntax error: '__int64' should be preceded by ';'
xtimec.h(32,25): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
xtimec.h(32,1): error C2086: 'int _CRTIMP2': redefinition
xtimec.h(28): message : see declaration of '_CRTIMP2'
xtimec.h(36,15): error C2144: syntax error: '__int64' should be preceded by ';'
xtimec.h(36,25): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
xtimec.h(36,1): error C2086: 'int _CRTIMP2': redefinition
xtimec.h(28): message : see declaration of '_CRTIMP2'
xtimec.h(37,15): error C2144: syntax error: '__int64' should be preceded by ';'
xtimec.h(37,25): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
xtimec.h(37,1): error C2086: 'int _CRTIMP2': redefinition
xtimec.h(28): message : see declaration of '_CRTIMP2'
chrono(28,55): error C2143: syntax error: missing ',' before '<'
chrono(29): message : see reference to class template instantiation 'std::chrono::treat_as_floating_point<_Rep>' being compiled
chrono(96,43): error C2143: syntax error: missing ';' before '<'
chrono(171): message : see reference to class template instantiation 'std::chrono::duration<_Rep,_Period>' being compiled
chrono(96,1): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
chrono(96,30): error C2126: 'std::chrono::duration<_Rep,_Period>::common_type_t' cannot be declared with 'constexpr' specifier
chrono(96,1): warning C4869: 'nodiscard' may only be applied to classes, enumerations, and functions
chrono(97,1): error C2334: unexpected token(s) preceding '{'; skipping apparent function body
chrono(101,43): error C2143: syntax error: missing ';' before '<'
chrono(101,1): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
chrono(101,30): error C2126: 'std::chrono::duration<_Rep,_Period>::common_type_t' cannot be declared with 'constexpr' specifier
chrono(101,1): warning C4869: 'nodiscard' may only be applied to classes, enumerations, and functions
chrono(102,1): error C2334: unexpected token(s) preceding '{'; skipping apparent function body
chrono(223,24): error C2143: syntax error: missing ',' before '<'
chrono(224): message : see reference to class template instantiation 'std::_Lcm<_Ax,_Bx>' being compiled
chrono(228,19): error C2988: unrecognizable template declaration/definition
chrono(228,19): error C2143: syntax error: missing ';' before '<'
chrono(228,19): error C2059: syntax error: '<'
chrono(228,37): error C2065: '_Rep1': undeclared identifier
chrono(228,44): error C2065: '_Period1': undeclared identifier
chrono(228,28): error C2923: 'std::chrono::duration': '_Rep1' is not a valid template type argument for parameter '_Rep'
chrono(228,28): error C2923: 'std::chrono::duration': '_Period1' is not a valid template type argument for parameter '_Period'
chrono(229,22): error C2065: '_Rep2': undeclared identifier
chrono(229,29): error C2065: '_Period2': undeclared identifier
chrono(229,13): error C2923: 'std::chrono::duration': '_Rep2' is not a valid template type argument for parameter '_Rep'
chrono(229,13): error C2923: 'std::chrono::duration': '_Period2' is not a valid template type argument for parameter '_Period'
chrono(229,40): error C2143: syntax error: missing ';' before '{'
chrono(229,40): error C2447: '{': missing function header (old-style formal list?)
chrono(235,8): error C2976: 'std::common_type': too few template arguments
chrono(228): message : see declaration of 'std::common_type'
chrono(238,2): error C2976: 'std::common_type': too few template arguments
chrono(236): message : see declaration of 'std::common_type'
chrono(243,39): error C2988: unrecognizable template declaration/definition
chrono(243,39): error C2143: syntax error: missing ';' before '<'
chrono(243,16): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
chrono(243,39): error C2059: syntax error: '<'
chrono(243,49): error C2065: '_Rep1': undeclared identifier
chrono(243,56): error C2065: '_Period1': undeclared identifier
chrono(243,40): error C2923: 'std::chrono::duration': '_Rep1' is not a valid template type argument for parameter '_Rep'
chrono(243,40): error C2923: 'std::chrono::duration': '_Period1' is not a valid template type argument for parameter '_Period'
chrono(243,76): error C2065: '_Rep2': undeclared identifier
chrono(243,83): error C2065: '_Period2': undeclared identifier
chrono(243,67): error C2923: 'std::chrono::duration': '_Rep2' is not a valid template type argument for parameter '_Rep'
chrono(243,67): error C2923: 'std::chrono::duration': '_Period2' is not a valid template type argument for parameter '_Period'
chrono(244,34): error C2065: '_Rep1': undeclared identifier
chrono(244,41): error C2065: '_Period1': undeclared identifier
chrono(244,25): error C2923: 'std::chrono::duration': '_Rep1' is not a valid template type argument for parameter '_Rep'
chrono(244,25): error C2923: 'std::chrono::duration': '_Period1' is not a valid template type argument for parameter '_Period'
chrono(244,74): error C2065: '_Rep2': undeclared identifier
chrono(244,81): error C2065: '_Period2': undeclared identifier
chrono(244,65): error C2923: 'std::chrono::duration': '_Rep2' is not a valid template type argument for parameter '_Rep'
chrono(244,65): error C2923: 'std::chrono::duration': '_Period2' is not a valid template type argument for parameter '_Period'
chrono(245,81): error C2143: syntax error: missing ';' before '{'
chrono(245,81): error C2447: '{': missing function header (old-style formal list?)
chrono(251,39): error C2988: unrecognizable template declaration/definition
chrono(251,39): error C2143: syntax error: missing ';' before '<'
chrono(251,16): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
chrono(251,26): error C2374: 'std::chrono::common_type_t': redefinition; multiple initialization
chrono(243): message : see declaration of 'std::chrono::common_type_t'
chrono(251,39): error C2059: syntax error: '<'
chrono(251,49): error C2065: '_Rep1': undeclared identifier
chrono(251,56): error C2065: '_Period1': undeclared identifier
chrono(251,40): error C2923: 'std::chrono::duration': '_Rep1' is not a valid template type argument for parameter '_Rep'
chrono(251,40): error C2923: 'std::chrono::duration': '_Period1' is not a valid template type argument for parameter '_Period'
chrono(251,76): error C2065: '_Rep2': undeclared identifier
chrono(251,83): error C2065: '_Period2': undeclared identifier
chrono(251,67): error C2923: 'std::chrono::duration': '_Rep2' is not a valid template type argument for parameter '_Rep'
chrono(251,67): error C2923: 'std::chrono::duration': '_Period2' is not a valid template type argument for parameter '_Period'
chrono(252,34): error C2065: '_Rep1': undeclared identifier
chrono(252,41): error C2065: '_Period1': undeclared identifier
chrono(252,25): error C2923: 'std::chrono::duration': '_Rep1' is not a valid template type argument for parameter '_Rep'
chrono(252,25): error C2923: 'std::chrono::duration': '_Period1' is not a valid template type argument for parameter '_Period'
chrono(252,74): error C2065: '_Rep2': undeclared identifier
chrono(252,81): error C2065: '_Period2': undeclared identifier
chrono(252,1): fatal error C1003: error count exceeds 100; stopping compilation
I created a fresh C++ (empty) project in VS2015, and then placed the Eigen 3.3.1 source code in an 'inc' folder in solution dir, such that the path to Matrix.h, for example, is inc/Eigen/Core/. I have set this inc/ path as an additional include directory, and have also tried with inc/Eigen/ as another include directory in case the files had issues including each other, but this changed nothing.
In main.cpp, I have the following:
#include "Eigen/Core/Matrix.h"
int main()
{
return 0;
}
This gives me, when compiling for x64:
1>c:\users\brody\documents\visual studio 2015\projects\eigentest\inc\eigen\core\matrix.h(18): error C2988: unrecognizable template declaration/definition
1>c:\users\brody\documents\visual studio 2015\projects\eigentest\inc\eigen\core\matrix.h(18): error C2143: syntax error: missing ';' before '<'
1>c:\users\brody\documents\visual studio 2015\projects\eigentest\inc\eigen\core\matrix.h(18): error C2059: syntax error: '<'
1>c:\users\brody\documents\visual studio 2015\projects\eigentest\inc\eigen\core\matrix.h(19): error C2143: syntax error: missing ';' before '{'
1>c:\users\brody\documents\visual studio 2015\projects\eigentest\inc\eigen\core\matrix.h(19): error C2447: '{': missing function header (old-style formal list?)
1>c:\users\brody\documents\visual studio 2015\projects\eigentest\inc\eigen\core\matrix.h(179): error C2143: syntax error: missing ',' before '<'
1> c:\users\brody\documents\visual studio 2015\projects\eigentest\inc\eigen\core\matrix.h(404): note: see reference to class template instantiation 'Eigen::Matrix<_Scalar,_Rows,_Cols,_Options,_MaxRows,_MaxCols>' being compiled
1>c:\users\brody\documents\visual studio 2015\projects\eigentest\inc\eigen\core\matrix.h(186): error C2143: syntax error: missing ';' before '<'
1>c:\users\brody\documents\visual studio 2015\projects\eigentest\inc\eigen\core\matrix.h(186): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\users\brody\documents\visual studio 2015\projects\eigentest\inc\eigen\core\matrix.h(186): error C2238: unexpected token(s) preceding ';'
1>c:\users\brody\documents\visual studio 2015\projects\eigentest\inc\eigen\core\matrix.h(192): error C2653: 'Base': is not a class or namespace name
1>c:\users\brody\documents\visual studio 2015\projects\eigentest\inc\eigen\core\matrix.h(192): error C2144: syntax error: 'int' should be preceded by ';'
1>c:\users\brody\documents\visual studio 2015\projects\eigentest\inc\eigen\core\matrix.h(192): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\users\brody\documents\visual studio 2015\projects\eigentest\inc\eigen\core\matrix.h(192): warning C4183: 'EIGEN_DENSE_PUBLIC_INTERFACE': missing return type; assumed to be a member function returning 'int'
1>c:\users\brody\documents\visual studio 2015\projects\eigentest\inc\eigen\core\matrix.h(192): error C3646: 'PlainObject': unknown override specifier
1>c:\users\brody\documents\visual studio 2015\projects\eigentest\inc\eigen\core\matrix.h(194): error C2653: 'Base': is not a class or namespace name
1>c:\users\brody\documents\visual studio 2015\projects\eigentest\inc\eigen\core\matrix.h(195): error C2653: 'Base': is not a class or namespace name
1>c:\users\brody\documents\visual studio 2015\projects\eigentest\inc\eigen\core\matrix.h(206): error C3646: 'EIGEN_STRONG_INLINE': unknown override specifier
1>c:\users\brody\documents\visual studio 2015\projects\eigentest\inc\eigen\core\matrix.h(206): error C3646: 'Matrix': unknown override specifier
1>c:\users\brody\documents\visual studio 2015\projects\eigentest\inc\eigen\core\matrix.h(206): error C2143: syntax error: missing ';' before '&'
1>c:\users\brody\documents\visual studio 2015\projects\eigentest\inc\eigen\core\matrix.h(206): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\users\brody\documents\visual studio 2015\projects\eigentest\inc\eigen\core\matrix.h(207): error C2334: unexpected token(s) preceding '{'; skipping apparent function body
1>c:\users\brody\documents\visual studio 2015\projects\eigentest\inc\eigen\core\matrix.h(223): error C2061: syntax error: identifier 'EIGEN_STRONG_INLINE'
1>c:\users\brody\documents\visual studio 2015\projects\eigentest\inc\eigen\core\matrix.h(237): error C2334: unexpected token(s) preceding '{'; skipping apparent function body
1>c:\users\brody\documents\visual studio 2015\projects\eigentest\inc\eigen\core\matrix.h(243): error C2061: syntax error: identifier 'EIGEN_STRONG_INLINE'
1>c:\users\brody\documents\visual studio 2015\projects\eigentest\inc\eigen\core\matrix.h(259): error C2334: unexpected token(s) preceding ':'; skipping apparent function body
1>c:\users\brody\documents\visual studio 2015\projects\eigentest\inc\eigen\core\matrix.h(14): fatal error C1075: the left brace '{' was unmatched at the end of the file
Which complains about line 18 of Matrix.h:
#ifndef EIGEN_MATRIX_H
#define EIGEN_MATRIX_H
namespace Eigen {
namespace internal {
template<typename _Scalar, int _Rows, int _Cols, int _Options, int _MaxRows, int _MaxCols>
struct traits<Matrix<_Scalar, _Rows, _Cols, _Options, _MaxRows, _MaxCols> > // line 18
{
private:
// etc...
Similar issues occur with any other Eigen #include. Have I missed some required #include ordering or some compile flag or setting? Thanks!
You must copy the entire Eigen directory not just the src subfolder. And you must not include files from the src subfolder directly, but include the files in the Eigen directory. E.g., #include <Eigen/Core> will include all core functionality, #include <Eigen/Dense> will include all dense functionality (this includes Core, Geometry and the decompositions).
I am making a DLL file for delphi applicaton in visual studio. I am following http://rvelthuis.de/articles/articles-cppobjs.html link to make the dll.My code is as follows
DLL_CLASS.h
#pragma once
using namespace std ;
#include "stdafx.h"
class DLL_CLASS
{
private:
public:
int TestValue;
char* getConnectedInverters (char* path);
char* getInverterParameters (int Device_Handle);
char* getInverter_SPOT_READINGS(int Device_Handle);
char* getPassword_varification();
char* get_Inverter_password();
char* get_Device_name(int Device_handle);
int get_Device_handel();
char* setAllInverterParameters(int Device_Handle,char* path_to_XML);
char* setYasdi_Reset_and_Shutdown();
char* get_Encryption(char* string_to_encrypt);
char* deviceXmlname();
char* RegExp(string Device_type);
int Get_inst_code_Channel(int Device_Handle);
char* set_One_InverterParameters(int Device_Handle,int Channel_handle,string Value);
DLL_CLASS();
virtual ~DLL_CLASS();
};
and other file code is as below
#include "stdafx.h"
#include "DLL_CLASS.h"
#include <tchar.h>
#include <windows.h>;
// define a macro for the calling convention and export type
#define EXPORTCALL __declspec(dllexport) __stdcall
typedef DLL_CLASS *ConsoleHandle;
extern "C"
{
ConsoleHandle EXPORTCALL NewConsole(void)
{
return new DLL_CLASS();
}
void EXPORTCALL DeleteConsole(ConsoleHandle handle)
{
delete handle;
}
char* EXPORTCALL NEW_getConnectedInverters(ConsoleHandle handle ,char* path)
{
handle->getConnectedInverters (path);
}
char* EXPORTCALL NEW_getInverterParameters (ConsoleHandle handle ,int Device_Handle)
{
handle->getInverterParameters(Device_Handle);
}
char* EXPORTCALL NEW_getInverter_SPOT_READINGS(ConsoleHandle handle,
int Device_Handle)
{
handle->getInverter_SPOT_READINGS(Device_Handle);
}
char* EXPORTCALL NEW_getPassword_varification(ConsoleHandle handle)
{
handle->getPassword_varification();
}
char* EXPORTCALL NEW_get_Inverter_password(ConsoleHandle handle)
{
handle->get_Inverter_password();
}
char* EXPORTCALL NEW_get_Device_name(ConsoleHandle handle,
int Device_handle)
{
handle->get_Device_name(Device_handle);
}
int EXPORTCALL NEW_get_Device_handel(ConsoleHandle handle)
{
return handle->get_Device_handel();
}
char* EXPORTCALL NEW_setAllInverterParameters(ConsoleHandle handle,int Device_Handle,char* path_to_XML)
{
return handle->setAllInverterParameters( Device_Handle, path_to_XML);
}
char* EXPORTCALL NEW_setYasdi_Reset_and_Shutdown(ConsoleHandle handle)
{
handle->setYasdi_Reset_and_Shutdown();
}
char* EXPORTCALL NEW_get_Encryption(ConsoleHandle handle,
char* string_to_encrypt)
{
handle->get_Encryption(string_to_encrypt);
}
char* EXPORTCALL NEW_deviceXmlname(ConsoleHandle handle)
{
handle->deviceXmlname();
}
char* EXPORTCALL RegExp(ConsoleHandle handle,
string Device_type)
{
handle->RegExp( Device_type);
}
char* EXPORTCALL NEW_set_One_InverterParameters(ConsoleHandle handle,
int Device_Handle,int Channel_handle,string Value)
{
handle->set_One_InverterParameters( Device_Handle,Channel_handle, Value);
}
int EXPORTCALL NEW_Get_inst_code_Channel(ConsoleHandle handle,
int Device_Handle)
{
handle->Get_inst_code_Channel(Device_Handle);
}
} // extern "C"
#pragma argsused
int WINAPI DllEntryPoint(HINSTANCE hinst, unsigned long reason, void* lpReserved)
{
return 1;
}
But this Give me error as below
1>------ Build started: Project: inverter_library, Configuration: Release Win32 ------
1> flatten.cpp
1>flatten.cpp(5): warning C4067: unexpected tokens following preprocessor directive - expected a newline
1>flatten.cpp(26): error C2059: syntax error : '__declspec(dllexport)'
1>flatten.cpp(27): error C2143: syntax error : missing ';' before '{'
1>flatten.cpp(27): error C2447: '{' : missing function header (old-style formal list?)
1>flatten.cpp(31): error C2059: syntax error : '__declspec(dllexport)'
1>flatten.cpp(32): error C2143: syntax error : missing ';' before '{'
1>flatten.cpp(32): error C2447: '{' : missing function header (old-style formal list?)
1>flatten.cpp(36): error C2059: syntax error : '__declspec(dllexport)'
1>flatten.cpp(38): error C2143: syntax error : missing ';' before '{'
1>flatten.cpp(38): error C2447: '{' : missing function header (old-style formal list?)
1>flatten.cpp(42): error C2059: syntax error : '__declspec(dllexport)'
1>flatten.cpp(43): error C2143: syntax error : missing ';' before '{'
1>flatten.cpp(43): error C2447: '{' : missing function header (old-style formal list?)
1>flatten.cpp(47): error C2059: syntax error : '__declspec(dllexport)'
1>flatten.cpp(48): error C2143: syntax error : missing ';' before '{'
1>flatten.cpp(48): error C2447: '{' : missing function header (old-style formal list?)
1>flatten.cpp(52): error C2059: syntax error : '__declspec(dllexport)'
1>flatten.cpp(54): error C2143: syntax error : missing ';' before '{'
1>flatten.cpp(54): error C2447: '{' : missing function header (old-style formal list?)
1>flatten.cpp(63): error C2059: syntax error : '__declspec(dllexport)'
1>flatten.cpp(64): error C2143: syntax error : missing ';' before '{'
1>flatten.cpp(64): error C2447: '{' : missing function header (old-style formal list?)
1>flatten.cpp(68): error C2059: syntax error : '__declspec(dllexport)'
1>flatten.cpp(69): error C2143: syntax error : missing ';' before '{'
1>flatten.cpp(69): error C2447: '{' : missing function header (old-style formal list?)
1>flatten.cpp(73): error C2059: syntax error : '__declspec(dllexport)'
1>flatten.cpp(75): error C2143: syntax error : missing ';' before '{'
1>flatten.cpp(75): error C2447: '{' : missing function header (old-style formal list?)
1>flatten.cpp(78): error C2059: syntax error : '__declspec(dllexport)'
1>flatten.cpp(79): error C2143: syntax error : missing ';' before '{'
1>flatten.cpp(79): error C2447: '{' : missing function header (old-style formal list?)
1>flatten.cpp(82): error C2059: syntax error : '__declspec(dllexport)'
1>flatten.cpp(84): error C2143: syntax error : missing ';' before '{'
1>flatten.cpp(84): error C2447: '{' : missing function header (old-style formal list?)
1>flatten.cpp(87): error C2059: syntax error : '__declspec(dllexport)'
1>flatten.cpp(89): error C2143: syntax error : missing ';' before '{'
1>flatten.cpp(89): error C2447: '{' : missing function header (old-style formal list?)
1>flatten.cpp(99): warning C4068: unknown pragma
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
Can anyone suggest me Why this error is coming
I tried to find the solution but I could not find it....
You need to place the __declspec(dllexport) before the return value, and the __stdcall after the return value. For example:
__declspec(dllexport) int __stdcall foo(...)
Your macro places them together, after the function return value. Hence the syntax error. So if you want both in a single macro, you need a parameterized macro that takes the return type as a parameter.
It's simpler and clear to be explicit and skip the macros and write it out longhand, in my view. I suggest that you shun macros unless they give significant benefit in comparison to non-macro alternatives. In this case I see no such benefit.
Note that some of your flattening functions are missing return statements. And you also need to be clear on the lifetime of the char* pointers that you return. I trust you are already on top of that.
I am setting up some framework for a little 2D game. Right now, I just have a few classes, but I am immediately falling into compiler problems.
I have run this program with only the main function, so I can confirm that the Allegro (graphics library) library linking has worked.
I have put all my header files (.h) under the "Header Files" section in the Solution explorer and all my source (.cpp) in the "Source Files" section. I have only modified settings from default as according to this Allegro tutorial: http://wiki.allegro.cc/index.php?title=Windows,_Visual_Studio_2010_and_Allegro_5. It should not have affected anything in a destructive way.
I have several files, so I will list each one. I will skip some code to reduce size and redundancy. When I omit any code or do anything not verbatim, I will put a comment in the code saying so. (EDIT: I actually did not skip any code)
main.cpp
#include "common.h"
int main(int argc, char **argv)
{
ALLEGRO_DISPLAY *display = NULL;
World* world = new World(640, 480);
if(!al_init()) {
fprintf(stderr, "failed to initialize allegro!\n");
return -1;
}
display = al_create_display(640, 480);
if(!display) {
fprintf(stderr, "failed to create display!\n");
return -1;
}
al_clear_to_color(al_map_rgb(0,0,0));
world->draw(display);
al_flip_display();
al_rest(10.0);
al_destroy_display(display);
return 0;
}
common.h
#if !defined(COMMON_INC)
#define COMMON_INC
#include "World.h"
#include "Pane.h"
#include <stdio.h>
#include <allegro5/allegro.h>
#endif
World.h
#if !defined(WORLD_INC)
#define WORLD_INC
#include "common.h"
#include "Pane.h"
class World{
public:
World(int wp, int hp);
void draw(ALLEGRO_DISPLAY* display);
void update();
protected:
private:
Pane* panel;
int heightPix, widthPix;
};
#endif
World.cpp
#include "common.h"
World::World(int wp, int hp){
widthPix = wp;
heightPix = hp;
panel = new Pane(this, 10, 10, 300, 400);
return;
}
void World::draw(ALLEGRO_DISPLAY* display){
panel->draw(display);
return;
}
Pane.h
#if !defined(PANE_INC)
#define PANE_INC
#include "common.h"
class Pane{
public:
Pane(World* w, int xv, int yv, int wi, int he);
World* getWorld();
int getZ();
void draw(ALLEGRO_DISPLAY* display);
ALLEGRO_BITMAP* getBackground();
protected:
void setXY(int xv, int yv);
void setWidthHeight(int wi, int he);
void setZ(int zv);
void setBackground(ALLEGRO_BITMAP* ba);
private:
int z;
int x, y; //pixels
int width, height; //pixels
World* world;
ALLEGRO_BITMAP* background;
};
#endif
Pane.cpp
#include "common.h"
Pane::Pane(World* w, int xv, int yv, int wi, int he){
this->setWidthHeight(wi, he);
this->setXY(xv, yv);
this->world = w;
}
World* Pane::getWorld(){
return world;
}
void Pane::setXY(int xv, int yv){
x = xv;
y = yv;
return;
}
void Pane::setWidthHeight(int wi, int he){\
width = wi;
height = he;
return;
}
void Pane::setZ(int zv){
z = zv;
return;
}
void Pane::draw(ALLEGRO_DISPLAY* display){
if(background != NULL)
al_draw_bitmap(background, x, y, 0);
else{
background = al_create_bitmap(width, height);
al_set_target_bitmap(background);
al_clear_to_color(al_map_rgb(255, 0, 255));
al_set_target_bitmap(al_get_backbuffer(display));
al_draw_bitmap(background, x, y, 0);
}
return;
}
The compiler produces this error report upon building: (I called the game madscientist because it is supposed to be alchemy-themed)
1>------ Build started: Project: MadScientist, Configuration: Debug Win32 ------
1> main.cpp
1>c:\users\ethoma\documents\visual studio 2012\projects\madscientist\madscientist\pane.h(8): error C2061: syntax error : identifier 'World'
1>c:\users\ethoma\documents\visual studio 2012\projects\madscientist\madscientist\pane.h(9): error C2143: syntax error : missing ';' before '*'
1>c:\users\ethoma\documents\visual studio 2012\projects\madscientist\madscientist\pane.h(9): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\users\ethoma\documents\visual studio 2012\projects\madscientist\madscientist\pane.h(9): warning C4183: 'getWorld': missing return type; assumed to be a member function returning 'int'
1>c:\users\ethoma\documents\visual studio 2012\projects\madscientist\madscientist\pane.h(11): error C2061: syntax error : identifier 'ALLEGRO_DISPLAY'
1>c:\users\ethoma\documents\visual studio 2012\projects\madscientist\madscientist\pane.h(12): error C2143: syntax error : missing ';' before '*'
1>c:\users\ethoma\documents\visual studio 2012\projects\madscientist\madscientist\pane.h(12): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\users\ethoma\documents\visual studio 2012\projects\madscientist\madscientist\pane.h(12): warning C4183: 'getBackground': missing return type; assumed to be a member function returning 'int'
1>c:\users\ethoma\documents\visual studio 2012\projects\madscientist\madscientist\pane.h(18): error C2061: syntax error : identifier 'ALLEGRO_BITMAP'
1>c:\users\ethoma\documents\visual studio 2012\projects\madscientist\madscientist\pane.h(24): error C2143: syntax error : missing ';' before '*'
1>c:\users\ethoma\documents\visual studio 2012\projects\madscientist\madscientist\pane.h(24): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\users\ethoma\documents\visual studio 2012\projects\madscientist\madscientist\pane.h(25): error C2143: syntax error : missing ';' before '*'
1>c:\users\ethoma\documents\visual studio 2012\projects\madscientist\madscientist\pane.h(25): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\users\ethoma\documents\visual studio 2012\projects\madscientist\madscientist\world.h(10): error C2061: syntax error : identifier 'ALLEGRO_DISPLAY'
1>c:\users\ethoma\documents\visual studio 2012\projects\madscientist\madscientist\main.cpp(22): error C2660: 'World::draw' : function does not take 1 arguments
1> World.cpp
1>c:\users\ethoma\documents\visual studio 2012\projects\madscientist\madscientist\pane.h(8): error C2061: syntax error : identifier 'World'
1>c:\users\ethoma\documents\visual studio 2012\projects\madscientist\madscientist\pane.h(9): error C2143: syntax error : missing ';' before '*'
1>c:\users\ethoma\documents\visual studio 2012\projects\madscientist\madscientist\pane.h(9): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\users\ethoma\documents\visual studio 2012\projects\madscientist\madscientist\pane.h(9): warning C4183: 'getWorld': missing return type; assumed to be a member function returning 'int'
1>c:\users\ethoma\documents\visual studio 2012\projects\madscientist\madscientist\pane.h(11): error C2061: syntax error : identifier 'ALLEGRO_DISPLAY'
1>c:\users\ethoma\documents\visual studio 2012\projects\madscientist\madscientist\pane.h(12): error C2143: syntax error : missing ';' before '*'
1>c:\users\ethoma\documents\visual studio 2012\projects\madscientist\madscientist\pane.h(12): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\users\ethoma\documents\visual studio 2012\projects\madscientist\madscientist\pane.h(12): warning C4183: 'getBackground': missing return type; assumed to be a member function returning 'int'
1>c:\users\ethoma\documents\visual studio 2012\projects\madscientist\madscientist\pane.h(18): error C2061: syntax error : identifier 'ALLEGRO_BITMAP'
1>c:\users\ethoma\documents\visual studio 2012\projects\madscientist\madscientist\pane.h(24): error C2143: syntax error : missing ';' before '*'
1>c:\users\ethoma\documents\visual studio 2012\projects\madscientist\madscientist\pane.h(24): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\users\ethoma\documents\visual studio 2012\projects\madscientist\madscientist\pane.h(25): error C2143: syntax error : missing ';' before '*'
1>c:\users\ethoma\documents\visual studio 2012\projects\madscientist\madscientist\pane.h(25): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\users\ethoma\documents\visual studio 2012\projects\madscientist\madscientist\world.h(10): error C2061: syntax error : identifier 'ALLEGRO_DISPLAY'
1>c:\users\ethoma\documents\visual studio 2012\projects\madscientist\madscientist\world.cpp(6): error C2661: 'Pane::Pane' : no overloaded function takes 5 arguments
1>c:\users\ethoma\documents\visual studio 2012\projects\madscientist\madscientist\world.cpp(10): error C2511: 'void World::draw(ALLEGRO_DISPLAY *)' : overloaded member function not found in 'World'
1> c:\users\ethoma\documents\visual studio 2012\projects\madscientist\madscientist\world.h(7) : see declaration of 'World'
1> Pane.cpp
1>c:\users\ethoma\documents\visual studio 2012\projects\madscientist\madscientist\pane.h(8): error C2061: syntax error : identifier 'World'
1>c:\users\ethoma\documents\visual studio 2012\projects\madscientist\madscientist\pane.h(9): error C2143: syntax error : missing ';' before '*'
1>c:\users\ethoma\documents\visual studio 2012\projects\madscientist\madscientist\pane.h(9): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\users\ethoma\documents\visual studio 2012\projects\madscientist\madscientist\pane.h(9): warning C4183: 'getWorld': missing return type; assumed to be a member function returning 'int'
1>c:\users\ethoma\documents\visual studio 2012\projects\madscientist\madscientist\pane.h(11): error C2061: syntax error : identifier 'ALLEGRO_DISPLAY'
1>c:\users\ethoma\documents\visual studio 2012\projects\madscientist\madscientist\pane.h(12): error C2143: syntax error : missing ';' before '*'
1>c:\users\ethoma\documents\visual studio 2012\projects\madscientist\madscientist\pane.h(12): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\users\ethoma\documents\visual studio 2012\projects\madscientist\madscientist\pane.h(12): warning C4183: 'getBackground': missing return type; assumed to be a member function returning 'int'
1>c:\users\ethoma\documents\visual studio 2012\projects\madscientist\madscientist\pane.h(18): error C2061: syntax error : identifier 'ALLEGRO_BITMAP'
1>c:\users\ethoma\documents\visual studio 2012\projects\madscientist\madscientist\pane.h(24): error C2143: syntax error : missing ';' before '*'
1>c:\users\ethoma\documents\visual studio 2012\projects\madscientist\madscientist\pane.h(24): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\users\ethoma\documents\visual studio 2012\projects\madscientist\madscientist\pane.h(25): error C2143: syntax error : missing ';' before '*'
1>c:\users\ethoma\documents\visual studio 2012\projects\madscientist\madscientist\pane.h(25): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\users\ethoma\documents\visual studio 2012\projects\madscientist\madscientist\world.h(10): error C2061: syntax error : identifier 'ALLEGRO_DISPLAY'
1>c:\users\ethoma\documents\visual studio 2012\projects\madscientist\madscientist\pane.cpp(3): error C2511: 'Pane::Pane(World *,int,int,int,int)' : overloaded member function not found in 'Pane'
1> c:\users\ethoma\documents\visual studio 2012\projects\madscientist\madscientist\pane.h(6) : see declaration of 'Pane'
1>c:\users\ethoma\documents\visual studio 2012\projects\madscientist\madscientist\pane.cpp(9): error C2556: 'World *Pane::getWorld(void)' : overloaded function differs only by return type from 'int *Pane::getWorld(void)'
1> c:\users\ethoma\documents\visual studio 2012\projects\madscientist\madscientist\pane.h(9) : see declaration of 'Pane::getWorld'
1>c:\users\ethoma\documents\visual studio 2012\projects\madscientist\madscientist\pane.cpp(9): error C2371: 'Pane::getWorld' : redefinition; different basic types
1> c:\users\ethoma\documents\visual studio 2012\projects\madscientist\madscientist\pane.h(9) : see declaration of 'Pane::getWorld'
1>c:\users\ethoma\documents\visual studio 2012\projects\madscientist\madscientist\pane.cpp(10): error C2065: 'world' : undeclared identifier
1>c:\users\ethoma\documents\visual studio 2012\projects\madscientist\madscientist\pane.cpp(30): error C2511: 'void Pane::draw(ALLEGRO_DISPLAY *)' : overloaded member function not found in 'Pane'
1> c:\users\ethoma\documents\visual studio 2012\projects\madscientist\madscientist\pane.h(6) : see declaration of 'Pane'
1> Generating Code...
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
You have all of the info that I do. I will summarize it for you to save the trouble of looking through everything.
There are classes separated into header interfaces and source implementations
common.h is included by all files. It itself includes all of the class definitions in the other header files
When compiled, the compiler does not recognize classes defined in other header files as data types. Errors, as you would expect, cascade down.
The real-time error checker does not register any errors. When hovering over the word "World" when it is used as a datatype in Pane, for example, it recognizes the type perfectly. The real-time error checker is the feature that red underlines errors before compiler time.
This Visual Studio 2012 Express is new except for the modifications mentioned earlier. The project was created as an empty C++ project. Before many headers and sources were add, the main function compiled correctly.
Thank you for any responses. If you have any questions, please ask. The problems I have with Visual Studio always irk me.
EDITS:
My circular header logic is guarded by the header guards. I don't think this redundancy is a problem.
I tried removing all includes from my header files except for includes to Allegro libraries. This seemed to work better, but there are still weird problems. Why the act of including is causing these data types to error is still a mystery. Here is the new error log:
1>------ Build started: Project: MadScientist, Configuration: Debug Win32 ------
1> main.cpp
1>c:\users\ethoma\documents\visual studio 2012\projects\madscientist\madscientist\world.h(16): error C2143: syntax error : missing ';' before '*'
1>c:\users\ethoma\documents\visual studio 2012\projects\madscientist\madscientist\world.h(16): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1> World.cpp
1>c:\users\ethoma\documents\visual studio 2012\projects\madscientist\madscientist\world.h(16): error C2143: syntax error : missing ';' before '*'
1>c:\users\ethoma\documents\visual studio 2012\projects\madscientist\madscientist\world.h(16): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\users\ethoma\documents\visual studio 2012\projects\madscientist\madscientist\world.cpp(6): error C2065: 'panel' : undeclared identifier
1>c:\users\ethoma\documents\visual studio 2012\projects\madscientist\madscientist\world.cpp(11): error C2065: 'panel' : undeclared identifier
1>c:\users\ethoma\documents\visual studio 2012\projects\madscientist\madscientist\world.cpp(11): error C2227: left of '->draw' must point to class/struct/union/generic type
1> type is ''unknown-type''
1> Pane.cpp
1>c:\users\ethoma\documents\visual studio 2012\projects\madscientist\madscientist\world.h(16): error C2143: syntax error : missing ';' before '*'
1>c:\users\ethoma\documents\visual studio 2012\projects\madscientist\madscientist\world.h(16): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1> Generating Code...
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
EDITS ROUND 2:
I switched my code around so the common.h only includes stdio and Allegro. All the header and source files include common.h and then any class's header file that they are using individually. Pane.cpp include Pane.h and common.h. World.h includes Pane.h and common.h.
Error log reads:
1>------ Build started: Project: MadScientist, Configuration: Debug Win32 ------
1> main.cpp
1>c:\users\ethoma\documents\visual studio 2012\projects\madscientist\madscientist\pane.h(9): error C2061: syntax error : identifier 'World'
1>c:\users\ethoma\documents\visual studio 2012\projects\madscientist\madscientist\pane.h(10): error C2143: syntax error : missing ';' before '*'
1>c:\users\ethoma\documents\visual studio 2012\projects\madscientist\madscientist\pane.h(10): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\users\ethoma\documents\visual studio 2012\projects\madscientist\madscientist\pane.h(10): warning C4183: 'getWorld': missing return type; assumed to be a member function returning 'int'
1>c:\users\ethoma\documents\visual studio 2012\projects\madscientist\madscientist\pane.h(25): error C2143: syntax error : missing ';' before '*'
1>c:\users\ethoma\documents\visual studio 2012\projects\madscientist\madscientist\pane.h(25): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1> World.cpp
1>c:\users\ethoma\documents\visual studio 2012\projects\madscientist\madscientist\pane.h(9): error C2061: syntax error : identifier 'World'
1>c:\users\ethoma\documents\visual studio 2012\projects\madscientist\madscientist\pane.h(10): error C2143: syntax error : missing ';' before '*'
1>c:\users\ethoma\documents\visual studio 2012\projects\madscientist\madscientist\pane.h(10): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\users\ethoma\documents\visual studio 2012\projects\madscientist\madscientist\pane.h(10): warning C4183: 'getWorld': missing return type; assumed to be a member function returning 'int'
1>c:\users\ethoma\documents\visual studio 2012\projects\madscientist\madscientist\pane.h(25): error C2143: syntax error : missing ';' before '*'
1>c:\users\ethoma\documents\visual studio 2012\projects\madscientist\madscientist\pane.h(25): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\users\ethoma\documents\visual studio 2012\projects\madscientist\madscientist\world.cpp(7): error C2661: 'Pane::Pane' : no overloaded function takes 5 arguments
1> Pane.cpp
1>c:\users\ethoma\documents\visual studio 2012\projects\madscientist\madscientist\world.h(16): error C2143: syntax error : missing ';' before '*'
1>c:\users\ethoma\documents\visual studio 2012\projects\madscientist\madscientist\world.h(16): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1> Generating Code...
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
This is how I see my include order now:
main includes common
common defines COMMON_INC
common includes stdio and allegro
main includes World.h
World defines WORLD_INC
World includes common, which is blocked. But this should be okay because common is already included
World includes Pane
Pane defines PANE_INC
Pane includes common, which is blocked. But this should be okay because common is already included.
Pane includes World. This is blocked because main already included World. Shouldn't this be okay since World was already included. Why do I even have compiler guards if I need to include files many times over, once for each file that uses it?
EDITS ROUND 3:
I have learned a lot from the answers and comments here. It turns out that, according to Wikipedia, "circular dependencies are often introduced by inexperienced programmers who need to implement some kind of callback functionality." The mere fact that Pane uses World and World uses Pane is a design flaw. In Java, this was all fine for me. It was very easy; I thought that this was the best way to notify the entity that "possesses" an object of the object's actions.
It turns out that this is a bad design scheme. Objects should not have dependencies to their "possessors". Instead, I need to implement a observer system, where the Pane can tell the World that it has updated its state.
Reading wikipedia cleared up any questions that I had, so I now consider this question finished. Thanks to the contributors for putting up for a learning programmer.
You header files cannot be possibly linked correctly. You included your headers in circular fashion. Your header files include common.h, while common.h in turn includes other headers, like World.h and Pane.h.
This is not compilable by any compiler. You have to develop a hierarchy of headers, from low-level headers to high-level headers and make sure that higher-level headers include only lower-level headers. That way you will make sure you have no circular inclusions.
Anyway, why does your common.h include World.h and Pane.h? This looks like an obvious error. common.h is intended to be a low-level header. Let World.h and Pane.h include it, but don't include World.h and Pane.h into common.h.
Note, that header guards do not solve anything in this case. They simply make sure that the inclusion cycle will not get infinite. They break the cycle, but they don't help you to resolve circular dependencies between declarations, if such dependencies exist.
Look what happens in your case when processing main.cpp
main.cpp includes common.h
common.h defines COMMON_INC
common.h includes World.h
World.h defines WORLD_INC
World.h includes common.h. The whole common.h is skipped by include guards, because COMMON_INC got defined at step 2.
World.h includes Pane.h
Pane.h defines PANE_INC
Pane.h includes common.h. The whole common.h is skipped by include guards, because COMMON_INC got defined at step 2.
Pane.h referred to type World. Type World is unknown, since we haven't gotten to its definition in World.h yet. Error!
I think everything will compile even with the circular includes, if you make the following changes
In common.h you need to rearrange order of headers.
#include <allegro5/allegro.h>
#include "World.h"
#include "Pane.h"
#include <stdio.h>
In pane.h, after the #include common.h, add a forward declaration for class World
#include "common.h"
class World;
class Pane{
.....
I think this will make your errors disappear or atleast decrease them substantially.
My answer is based on the original code you put up, not on the Edit.
I have this code from programming pearls
#include <iostream>
//#include <string>
using namespace std;
template <class T>
void measure(char *text)
{
cout<<"measure"<<text<<"\t";
cout<<sizeof(t)<<"\n";
}
#define MEASURE(T,text){
cout<<text<<"\t";
cout<<sizeof(T)<<"\t";
int lastp=0;
for (int i=0;i<11;i++){
T *p=new T;
int thisp=(int)p;
if (lastp!=0)
cout<<" "<<thisp-lastp;
lastp=thisp;
}
cout<<"n":
}
int main(){
return 0;
}
but there are some mistakes
1>------ Build started: Project: new_practises, Configuration: Debug Win32 ------
1> practises.cpp
1>c:\users\david\documents\visual studio 2010\projects\new_practises\practises.cpp(11): error C2143: syntax error : missing ';' before '<<'
1>c:\users\david\documents\visual studio 2010\projects\new_practises\practises.cpp(11): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\users\david\documents\visual studio 2010\projects\new_practises\practises.cpp(12): error C2143: syntax error : missing ';' before '<<'
1>c:\users\david\documents\visual studio 2010\projects\new_practises\practises.cpp(12): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\users\david\documents\visual studio 2010\projects\new_practises\practises.cpp(12): error C2086: 'int cout' : redefinition
1> c:\users\david\documents\visual studio 2010\projects\new_practises\practises.cpp(11) : see declaration of 'cout'
1>c:\users\david\documents\visual studio 2010\projects\new_practises\practises.cpp(14): error C2059: syntax error : 'for'
1>c:\users\david\documents\visual studio 2010\projects\new_practises\practises.cpp(14): error C2143: syntax error : missing ')' before ';'
1>c:\users\david\documents\visual studio 2010\projects\new_practises\practises.cpp(14): error C2143: syntax error : missing ';' before '<'
1>c:\users\david\documents\visual studio 2010\projects\new_practises\practises.cpp(14): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\users\david\documents\visual studio 2010\projects\new_practises\practises.cpp(14): error C2143: syntax error : missing ';' before '++'
1>c:\users\david\documents\visual studio 2010\projects\new_practises\practises.cpp(14): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\users\david\documents\visual studio 2010\projects\new_practises\practises.cpp(14): error C2086: 'int i' : redefinition
1> c:\users\david\documents\visual studio 2010\projects\new_practises\practises.cpp(14) : see declaration of 'i'
1>c:\users\david\documents\visual studio 2010\projects\new_practises\practises.cpp(14): error C2059: syntax error : ')'
1>c:\users\david\documents\visual studio 2010\projects\new_practises\practises.cpp(14): error C2143: syntax error : missing ';' before '{'
1>c:\users\david\documents\visual studio 2010\projects\new_practises\practises.cpp(14): error C2447: '{' : missing function header (old-style formal list?)
1>c:\users\david\documents\visual studio 2010\projects\new_practises\practises.cpp(21): error C2143: syntax error : missing ';' before '<<'
1>c:\users\david\documents\visual studio 2010\projects\new_practises\practises.cpp(21): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\users\david\documents\visual studio 2010\projects\new_practises\practises.cpp(21): error C2086: 'int cout' : redefinition
1> c:\users\david\documents\visual studio 2010\projects\new_practises\practises.cpp(11) : see declaration of 'cout'
1>c:\users\david\documents\visual studio 2010\projects\new_practises\practises.cpp(22): error C2059: syntax error : '}'
1>c:\users\david\documents\visual studio 2010\projects\new_practises\practises.cpp(22): error C2143: syntax error : missing ';' before '}'
1>c:\users\david\documents\visual studio 2010\projects\new_practises\practises.cpp(22): error C2059: syntax error : '}'
1>c:\users\david\documents\visual studio 2010\projects\new_practises\practises.cpp(24): error C2143: syntax error : missing ';' before '{'
1>c:\users\david\documents\visual studio 2010\projects\new_practises\practises.cpp(24): error C2447: '{' : missing function header (old-style formal list?)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
What do I need to fix?
DeadMG is correct, there are quite a few mistakes here. The most prominent one is that you are not using #define correctly. It requires that all of the code of the function goes on one line.
#define func(A, B) {//function body goes here}
To allow multi-line #defines, use \s at the end of the lines:
#define MEASURE(T,text) {\
cout<<text<<"\t";\
cout<<sizeof(T)<<"\t";\
int lastp=0;\
for (int i=0;i<11;i++){\
T *p=new T;\
int thisp=(int)p;\
if (lastp!=0) cout<<" "<<thisp-lastp;\
lastp=thisp;\
}\
cout<<"n";\
}
(Note I have fixed a few typos here, including one : where a ; should be.)
The other big problem with your code is in the measure function:
void measure(char *text)
{
cout<<"measure"<<text<<"\t";
cout<<sizeof(t)<<"\n";
}
What is t? I assume you mean text, not t.
The following should compile okay.
#include <iostream>
#define MEASURE(T,text) {\
cout<<text<<"\t";\
cout<<sizeof(T)<<"\t";\
int lastp=0;\
for (int i=0;i<11;i++){\
T *p=new T;\
int thisp=(int)p;\
if (lastp!=0) cout<<" "<<thisp-lastp;\
lastp=thisp;\
}\
cout<<"n";\
}
using namespace std;
template <class T>
void measure(char *text)
{
cout<<"measure"<<text<<"\t";
cout<<sizeof(text)<<"\n";
}
int main() {
return 0;
}
As a final, not directly bug-related question to you - why are you using a #define like this? Why not simply write the #define code into the measure method? #defineis usually used to give a short name for a variable or to declare very small functions - and there is a vocal part of the community that thinks they shouldn't be used at all!
In addition to Stephen's answer, I can say that #define is un-C++ish. It becomes useful when you need a variable name that corresponds to a string or something the like. For mostly all other cases, use functions.
Next to that, I must concur with DeadMG's opinion that at least I'm too stupid to see any reason to write this function. But that's another concern :)
If you actually want to measure the length of a string, you can use the function strlen.
What your MEASURE seems to do is print out a series of 11 newly allocated memory addresses. Nice to do when you are studying the memory allocation strategy of your runtime, but otherwise not too useful.
Also don't forget to delete what you have newed.
#define MEASURE(T,text) {\
cout<<text<<"\t";\
cout<<sizeof(T)<<"\t";\
...
can be directly translated into a template function: way easier to write, and to debug.
template< typename T > // assuming you _need_ a variable type of arguments
void MEASURE( const T& text) {
cout<<text<<"\t";
cout<<sizeof(T)<<"\t";
// will write the size of e.g. one character. Maybe
// you should use strlen or the like...
int lastp=0;
for (int i=0;i<11;i++){
T *p=new T;
int thisp=(int)p;
if (lastp!=0) cout<<" "<<thisp-lastp;
lastp=thisp;
}
cout<<"n";
}
"some" mistakes? Whoever wrote that has NFI what on earth they're doing. The program doesn't even produce any meaningful output. ... or any output at all. You could literally not run it or read the source code and gain the same knowledge: zero.
You need to add "\" at the end of the line when your definition across multiple lines.
Below code is compiled with no errors.
#include "stdafx.h"
#include <iostream>
using namespace std;
template <class T>
void measure(char *text)
{
cout<<"measure"<<text<<"\t";
cout<<sizeof(t)<<"\n";
}
#define MEASURE(T,text) { \
cout<<text<<"\t"; \
cout<<sizeof(T)<<"\t"; \
int lastp=0; \
for (int i=0;i<11;i++){ \
T *p=new T; \
int thisp=(int)p; \
if (lastp!=0) \
cout<<" "<<thisp-lastp; \
lastp=thisp; \
} \
cout<<"n": \
}
int main(){
return 0;
}