意外的非限定 ID 错误
unexpected unqualified id error
expected unqualified-id before string constant in member function set_linux().
我在编译代码期间收到此错误。我在这里添加了类和主函数。
expected before '}' before end of line
法典:
#include "Timer.h"
Timer::Timer() {
now = 0;
is_init = 0;
#if defined (_linux)
set_linux();
#elif defined (_APPLE)
set_apple();
#elif defined (_WIN32)
set_win32();
#endif // defined
}
void Timer::set_apple() {
#define HAVE_MACH_TIMER
//#include <mach/mach_time.h>
}
void Timer::set_linux() {
#define HAVE_POSIX_TIMER
#include <time.h>
#ifdef CLOCK_MONOTONIC
#define CLOCKID CLOCK_MONOTONIC
#else
#define CLOCKID CLOCK_REALTIME
#endif // CLOCK_MONOTONIC
}
void Timer::set_win32() {
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
}
void Timer::apple() {
static mach_timebase_info_data_t info;
if (0 == is_init) {
mach_timebase_info(&info);
is_init = 1;
}
now = mach_absolute_time();
now *= info.numer;
now /= info.denom;
}
void Timer::linux() {
static struct timespec linux_rate;
if (0 == is_init) {
clock_getres(CLOCKID, &linux_rate);
is_init = 1;
}
struct timespec spec;
clock_gettime(CLOCKID, &spec);
now = spec.tv_sec * 1.0e9 + spec.tv_nsec;
}
void Timer::win32() {
static LARGE_INTEGER win_frequency;
if (0 == is_init) {
QueryPerformanceFrequency(&win_frequency);
is_init = 1;
}
LARGE_INTEGER now;
QueryPerformanceCounter(&now);
this->now = (uint64_t) ((1e9 * now.QuadPart) / win_frequency.QuadPart);
}
static uint64_t Timer::ns() {
#if defined (_APPLE_)
apple();
return now;
#elif defined (_linux)
linux();
return now;
#elif defined(_WIN32)
win32();
return now;
#endif // defined
}
using namespace std;
int main() {
return 0;
}
你不应该在函数或命名空间范围内 #include 东西,因为这会使它更难看到(在这种情况下,你是在局部作用域下定义它的内容,而不是它们所在的全局作用域(。 此外,您正在执行的操作会导致每个平台上的编译问题。 您可能想要的是有条件地 #include 并根据顶部的平台 #define 您的价值观。
#include "Timer.h"
#if defined (_linux)
# define HAVE_POSIX_TIMER
# include <time.h>
# ifdef CLOCK_MONOTONIC
# define CLOCKID CLOCK_MONOTONIC
# else
# define CLOCKID CLOCK_REALTIME
# endif // CLOCK_MONOTONIC
#elif defined (_APPLE)
# define HAVE_MACH_TIMER
//# include <mach/mach_time.h>
#elif defined (_WIN32)
# define WIN32_LEAN_AND_MEAN
# include <windows.h>
#endif
Timer::Timer() {
now = 0;
is_init = 0;
// This portion may no longer be applicable.
#if defined (_linux)
set_linux();
#elif defined (_APPLE)
set_apple();
#elif defined (_WIN32)
set_win32();
#endif // defined
}
void Timer::set_apple() {
}
void Timer::set_linux() {
}
void Timer::set_win32() {
}
void Timer::apple() {
static mach_timebase_info_data_t info;
if (0 == is_init) {
mach_timebase_info(&info);
is_init = 1;
}
now = mach_absolute_time();
now *= info.numer;
now /= info.denom;
}
void Timer::linux() {
static struct timespec linux_rate;
if (0 == is_init) {
clock_getres(CLOCKID, &linux_rate);
is_init = 1;
}
struct timespec spec;
clock_gettime(CLOCKID, &spec);
now = spec.tv_sec * 1.0e9 + spec.tv_nsec;
}
void Timer::win32() {
static LARGE_INTEGER win_frequency;
if (0 == is_init) {
QueryPerformanceFrequency(&win_frequency);
is_init = 1;
}
LARGE_INTEGER now;
QueryPerformanceCounter(&now);
this->now = (uint64_t) ((1e9 * now.QuadPart) / win_frequency.QuadPart);
}
static uint64_t Timer::ns() {
#if defined (_APPLE_)
apple();
return now;
#elif defined (_linux)
linux();
return now;
#elif defined(_WIN32)
win32();
return now;
#endif // defined
}
using namespace std;
int main() {
return 0;
}
相关文章:
- 我不断收到 [错误] ID 返回 1 退出状态错误,但看不到问题所在
- 方法内部但循环仍得到预期的不合格id错误C++
- Xcode 9.4.1 中的 Apple Mach-O 链接器 (id) 错误
- 错误:令牌 { '{' 之前应存在非限定 ID
- DCMTK 了解"DIMSE 没有有效的演示上下文 ID"错误
- C++中的"expected unqualified-id"错误是什么?
- c++ for 循环中预期的非限定 id 错误
- 在"." 令牌之前应为非限定 ID(C++ 错误)
- 预期"{"错误?以及预期的未指定 ID 错误?
- 错误:预期的非限定 ID 错误:含义和修复
- 安卓-NDK-R7C "deque.h"中的非限定 ID 错误
- 预期的不合格id错误,很可能是原因
- 意外的非限定 ID 错误
- C++中类出现预期的不合格id错误
- 出现意外的非限定id错误
- iOS中出现不合格的id错误
- XSLT到HTML的转换.Qt5中的generate-id()错误
- 不合格的id错误和井字游戏板不工作
- 传递结构体数组的预期非限定id错误
- 如何执行项目范围内的唯一id /错误代码,以便在源代码中轻松找到错误的来源