我正在处理一项任务,并且在以下代码中不断出现分段错误main
,我们不允许更改:
char signal[61];
Seti t2A(data, rF, rA, rB); // call constructor
t2A.getMessage(signal); // calling member functions
t2A.getRanges(&pA, &pB);
usrF = t2A.getFrequency( );
if(strcmp(signal, correct)) { // <-- this is where i get segmentation fault.
类的实现Seti
:
class Seti {
char signal[61];
int freq;
int a, b;
public:
Seti(const char [ ], int, int, int);
Seti();
int getFrequency( );
void getRanges(int *, int *);
void setRanges(int , int );
void getMessage(char *);
bool replaceChar(int , char );
bool copyPrimes(char *);
bool copyFibonacci(char *);
int initCap( );
friend Seti join(Seti, Seti);
};
并执行getMessage
:
void Seti::getMessage(char *pSignal) {
strcpy (pSignal, signal);
return;
}
为什么在 main 中的 if 语句之后我会收到分段错误?