【发布时间】:2019-05-22 22:11:43
【问题描述】:
我正在使用cmake 构建一个数据结构项目,并构建了一个数组类。
我使用std::size_t 作为默认构造函数的参数。
但是当我尝试构建项目时,会出现一个错误,提示 Invalid use of ::
我尝试了using namespace std;,但也没有成功。
barra.h 文件
#ifndef BARRAY_H
#define BARRAY_H
class BArray
{
public:
BArray() = delete; //Declare the default constructor as deleted to avoid
//declaring an array without specifying its size.
BArray(std::size_t);
BArray(int, int); //Constructor that initializes the array with init_val.
private:
int* array;
int length;
};
#endif // BARRAY_H
还有barray.cpp
#include <iostream>
#include "barray.h"
BArray::BArray(std::size_t init_size)
{
array = new int[init_size]();
length = init_size;
}
BArray::BArray(int init_size, int init_val)
{
array = new int[init_size];
length = init_size;
for(int i = 0; i < init_size; ++i)
array[i] = init_val;
}
错误信息:
错误::: 的使用无效
【问题讨论】:
-
您是否包含任何内容,或者您的头文件是否完全按照原样?
-
@Tas 不,头文件完全一样。
-
@BilalAhmed No repro。请根据需要发布minimal reproducible example重现问题。
-
如果你要使用它,你的头文件需要包含
std::size_t的定义位置。 -
请参阅this 了解您可以使用的包含。
标签: c++ build cmake std gnu-make