C++ 为什么赢了';这不是在我的unix系统上编译的吗?
我在家里完成了一项在编译器上运行良好的作业,但当我把它上传到学校的linux系统时,我无法让它编译 下面是我得到的错误:C++ 为什么赢了';这不是在我的unix系统上编译的吗?,c++,unix,g++,C++,Unix,G++,我在家里完成了一项在编译器上运行良好的作业,但当我把它上传到学校的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 ‘
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;
}
#包括“Set.h”
Set::Set()
{
int i;
对于(i=0;i我认为问题在于以下代码:
#include "Set.h"
Set::Set()
{
int i;
for(i = 0; i <= 3; i++)
bitString[i] = 0;
}
Set::Set(const Set& s)
{
}
Set::~Set()
{
我认为问题出在以下代码中:
#include "Set.h"
Set::Set()
{
int i;
for(i = 0; i <= 3; i++)
bitString[i] = 0;
}
Set::Set(const Set& s)
{
}
Set::~Set()
{
您没有用于析构函数的}
。谢谢,这样一个愚蠢的错误!您没有用于析构函数的}
。谢谢,这样一个愚蠢的错误!