为什么这不能在我的学校 unix 系统上编译?
Why won't this compile on my schools unix system?
我在家里完成了一项作业,在我的编译器上运行良好,但是当我将其上传到学校的Linux系统时,我无法对其进行编译。
这是我得到的错误:
Set.cpp: In destructor ‘Set::~Set()’:
Set.cpp:42:1: error: a function-definition is not allowed here before ‘{’ token
Set.cpp:55:1: error: a function-definition is not allowed here before ‘{’ token
Set.cpp:67:1: error: a function-definition is not allowed here before ‘{’ token
Set.cpp:193:1: error: expected ‘}’ at end of input
我不确定这里发生了什么,但我的程序在代码块中编译得很好。
#include "Set.h"
Set::Set()
{
int i;
for(i = 0; i <= 3; i++)
bitString[i] = 0;
}
Set::Set(const Set& s)
{
}
Set::~Set()
{
//Functions for modifying the sets individually:
void Set::add(int i)
{
unsigned int mask;
int bit, word;
word = i / 32;
bit = i % 32;
mask = 1 << bit;
bitString[word] |= mask;
}
void Set::remove(int i)
{
unsigned int mask;
int bit, word;
word = i / 32;
mask = (1 << (i % 32)) ;
bitString[word] &= ~(mask);
}
int Set::size()
{
unsigned size = 0;
for (unsigned i = 0; i <= 3; ++i)
{
for (unsigned x = 0; x < 32; ++x)
{
if (bitString[i] & (1 << x))
++size;
}
}
cout << "Size of this set is: " << size << endl;
return size;
}
int Set::is_member(int i)
{
int bit, word;
word = i / 32;
bit = i % 32;
if((bitString[word] >> bit) & 1)
return 1;
else
return 0;
}
//Operators Defined here:
void Set::operator=(const Set& s)
{
int bits;
for (bits = 0; bits <= 3; bits++)
{
bitString[bits] = s.bitString[bits];
}
}
Set Set::operator-(const Set& s)
{
Set result;
int x;
for (x = 0; x <= 3; x++)
{
result.bitString[x] = (bitString[x] & ~s.bitString[x]);
}
return result;
}
Set Set::operator&(const Set& s)
{
Set result;
int x;
for (x = 0; x <= 3; x++)
{
result.bitString[x] = (bitString[x] & s.bitString[x]);
}
return result;
}
Set Set::operator|(const Set& s)
{
Set result;
int x;
for (x = 0; x <= 3; x++)
{
result.bitString[x] = (bitString[x] | s.bitString[x]);
}
return result;
}
// XOR
Set Set::operator^(const Set& s)
{
Set result;
int x;
for (x = 0; x <= 3; x++)
{
result.bitString[x] = (bitString[x] ^ s.bitString[x]);
}
return result;
}
// Print Result
void Set::printSet()
{
unsigned size = 0;
cout << "Set: { b";
for (unsigned i = 0; i <= 3; ++i)
{
for (unsigned x = 0; x < 32; ++x)
{
if (bitString[i] & (1 << x))
cout << (x + (i * 32)) << ",";
}
}
cout << "b}" << endl;
}
我认为问题出在以下代码中:
#include "Set.h"
Set::Set()
{
int i;
for(i = 0; i <= 3; i++)
bitString[i] = 0;
}
Set::Set(const Set& s)
{
}
Set::~Set()
{
在析构函数中,您忘记关闭括号。这就是编译器抱怨的。它不会在任何系统中运行。您可以将其修改为:
Set::~Set()
{
}
相关文章:
- 获取 clang++:错误:在编译文件系统库的代码时
- 减少使用 GSL 用于 ODE 系统的编译资源
- 编译了一个recent-C++.因此,如果没有暴露std符号,请在旧系统上运行
- 将 std::文件系统头文件添加到我的程序时出现编译错误
- 为什么 boost 文件系统和 libpq-fe 标头不会在同一个文件中编译
- 在C++中读取文件系统时出现问题(Boost 未编译)
- 针对 QNX 交叉编译后,boost 文件系统 (1.63) 失败并出现未定义的引用错误
- OPENCV 3.2是否与CUDA 10兼容?我如何在使用CUDA 10的系统上编译和构建OpenCV 3.2
- X86系统的编译读取线(静态模式)
- 添加 boost 文件系统.hpp 无法编译
- C++构建系统 - 远程编译和链接选项
- MinGW 编译的可执行文件与网络无法在 x64 系统上运行
- Linux 系统调用 + 交叉编译
- 在编译系统中,链接器(ld)如何知道将myprogram.o链接到谁
- 我无法编译文件系统库
- 在安装了两个不同 Boost 版本的系统上编译C++代码
- Simple_ls.cpp的C++Boost编译错误-未找到对Boost的引用::文件系统::路径::文件名
- 覆盖来自 R 的C++编译标志的系统默认值
- 编译 boost 文件系统的教程文件时遇到问题
- 如何为大多数系统编译LD_PRELOAD