我包含 cstdarg 并收到以下错误:
expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘attribute’ before ‘{’ token"
错误发生在以下行:
using ::va_list;
这里是cstdarg的内容:
#pragma GCC system_header
#include </usr/include/c++/4.6.3/x86_64-linux-gnu/bits/c++config.h>
#include <stdarg.h>
#ifndef _GLIBCXX_CSTDARG
#define _GLIBCXX_CSTDARG 1
// Adhere to section 17.4.1.2 clause 5 of ISO 14882:1998
#ifndef va_end
#define va_end(ap) va_end (ap)
#endif
namespace std
{
using ::va_list; I get the error here!
} // namespace std
#endif
在此文件中调用了 va_list :
#include <fcntl.h>
#include <unistd.h>
#include </usr/include/c++/4.6.3/tr1/stdarg.h>
#include <stdlib.h>
#include <sys/ioctl.h>
#include <errno.h>
#include <sys/types.h>
#include <sys/stat.h>
#include </usr/include/x86_64-linux-gnu/bits/errno.h>
#include "string.h"
#include "libnitro.h"
#include "nitro.h"
#define KVM_NODE "/dev/kvm"
int kvm_fd;
int kvm_vmfd;
struct nitro_vcpus vcpus;
int kvm_ioctl(int type, ...)
{
int ret;
void *arg;
va_list ap;
va_start(ap, type);
arg = va_arg(ap, void *);
va_end(ap);
ret = ioctl(kvm_fd, type, arg);
if (ret == -1)
ret = -errno;
return ret;
}
int kvm_vm_ioctl(int type, ...)
{
int ret;
void *arg;
va_list ap;
va_start(ap, type);
arg = va_arg(ap, void *);
va_end(ap);
ret = ioctl(kvm_vmfd, type, arg);
if (ret == -1)
ret = -errno;
return ret;
}
int kvm_vcpu_ioctl(int vcpu_fd,int type, ...){
int ret;`
` void *arg;`
` va_list ap;`
va_start(ap, type);
arg = va_arg(ap, void *);
va_end(ap);
ret = ioctl(vcpu_fd, type, arg);
if (ret == -1)
ret = -errno;
return ret;
}
int kvm_ioctl(int type, ...)
{
int ret;
void *arg;
va_list ap;
va_start(ap, type);
arg = va_arg(ap, void *);
va_end(ap);
ret = ioctl(kvm_fd, type, arg);
if (ret == -1)
ret = -errno;
return ret;
}
最佳答案
您应该使用 g++
而不是 gcc
编译您的 c++ 代码。
此外,大多数用户(和程序)希望以.c
结尾的文件(如libnitro.c
)使用C 语言,而不是C++ 语言。对于 C++ 源代码,您应该将文件命名为 libnitro.cpp
或 libnitro.cc
。
关于c++ - ‘=’ , ‘,’ , ‘;’ , ‘asm’ 或 ‘__attribute__’ 在 ‘{’ token 之前,当我使用::va_list时;,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24142129/