这
//CSocket.h
#ifndef __SERVER_CSOCKET_H__
#define __SERVER_CSOCKET_H__
#include "winsock2.h"
#include "ws2tcpip.h"
#include <thread>
#include <stdio.h>
#include <string>(cpp只包括报头)
//CSocket.cpp
#include "CSocket.h"在c中生成以下错误消息:\程序文件(X86)\12.0\vc\包含\比率
ratio(122): error C2065: 'INTMAX_MAX': undeclared identifier
ratio(133): See reference to the instance of the just compiled class-template "std::ratio<_Nx,_Dx>".
ratio(124): error C2065: 'INTMAX_MAX': undeclared identifier
ratio(44): error C2065: 'INTMAX_MAX': undeclared identifier
ratio(217): See reference to the instance of the just compiled class-template "std::_Safe_mult<0x01,0x01>".
ratio(36): error C2338: integer arithmetic overflow
ratio(44): See reference to the instance of the just compiled class-template "std::_Safe_multX<0x01,0x01,false>".
ratio(44): error C2039: 'value': Is not an element of 'std::_Safe_multX<0x01,0x01,false>'
ratio(44): error C2065: 'value': undeclared identifier
ratio(44): error C2057: Expected constant expression
ratio(44): error C2039: 'value': Is not an element of 'std::_Safe_multX<0x01,0x0989680,false>'
ratio(219): error C2975: "_Nx": invalid template argument for "std::ratio", expected compile-time constant expression.
ratio(116): See declaration of '_Nx'
ratio(219): error C2975: "_Dx": invalid template argument for "std::ratio", expected compile-time constant expression.
ratio(117): See declaration of '_Dx'
CSocket.cpp包括std::.cpp中的线程而不是头中的线程解决了所有的错误,但是我不知道为什么它不能在头中工作。
//CSocket.cpp
#include "CSocket.h"
#include <thread>我使用的唯一库是jemalloc。错误是否来自在互斥之前包含jemalloc.h,而不是线程本身?
发布于 2015-02-26 20:55:03
我必须在#include <mutex>之前#include "jemalloc.h",而不是以后。现在工作很好,但是有一些奇怪的错误。
发布于 2015-03-09 19:00:13
我也有同样的错误,但是包含的顺序对我没有用。我认为这与其他也使用计时和线程的内容有关,所以您可以查看它。
您在使用吗?似乎有更多的人犯了同样的错误:https://connect.microsoft.com/VisualStudio/feedback/details/800726/compiler-error
发布于 2016-06-29 13:46:06
我在VS2013更新3中也有同样的错误。问题似乎是INTMAX_MAX没有定义,但它被使用在ratio.h中。
我的解决办法是
#define INTMAX_MAX INT64_MAX在文件中的#include <ratio>之前(如果没有行,可以添加它)。
要包含的行可以在stdint.h中找到--在您的示例中,右侧可以是不同的。
PS另一种解决方案是#include <stdint.h>和定义__STDC_LIMIT_MACROS。在这种情况下,您可能会收到一些关于重复宏的警告。
https://stackoverflow.com/questions/28732739
复制相似问题