I'm just getting started, but I'm already having trouble. So far, my code is simply:
(In Searcher开发者_JAVA百科.h)
#ifndef SEARCHER_H
#define SEARCHER_H
#include <string>
#include <list>
using namespace std;
class Searcher{
public:
Searcher( int& x );
~Searcher();
private:
int size;
list<string> * lists;
};
#endif
(In Searcher.cpp)
#include "Searcher.h"
Searcher::Searcher (int& x){
lists = new list<string>[x];
}
(In testSearcher.cpp)
#include "Searcher.h"
#include <iostream>
using namespace std;
int main (){
Searcher * x = new Searcher(211);
}
It compiles, but when I run it, it gives a floating point exception. I even replaced x with 211 to no avail. Thank you in advance for any help. Also, to amateur debug it, I put a cout statement in the constructor before the initialization and it printed fine, then g++ gave me the floating point exception.
Try making the parameter to Searcher "const int &x".
Shouldn't it be:
Searcher::Searcher (int& x) {
lists = new list<string>(x);
}
I've never seen the syntax you posted with the [x].
精彩评论