This question should be pretty simple, maybe stupid, but I just can't find the problem.
Basically, I have to parse some sentences in natural language. I need to implement a simple algorithm that manipulates "Blocks". The block consists of 2 pseudo-cases, which consist of 20 words (lines).
Here is the code:
typedef vector<string> Pseudosentence; #define W 20 // A Pseudosentence is made of W words #define K 2 // A block is made of K Pseudosentences class Block { public: vector<Pseudosentence> p; multimap<string, int> Scoremap; Block() { p.resize(2); } Block(Pseudosentence First, Pseudosentence Second){ p.resize(2); p[0] = First; p[1] = Second; } void rankTerms(); // Calculates some ranking function void setData(Pseudosentence First, Pseudosentence Second){ p[0] = First; p[1] = Second; } }; stringstream str(final); // Final contains the (preprocessed) text. string t; vector<Pseudosentence> V; // V[j][i]. Every V[j] is a pseudosentence. Every V[j][i] is a word (string). vector<Block> Blocks; vector<int> Score; Pseudosentence Helper; int i = 0; int j = 0; while (str) { str >> t; Helper.push_back(t); i++; //cout << Helper[i]; if (i == W) { // When I have a pseudosentence... V.push_back(Helper); j++; // This measures the j-th pseudosentence Helper.clear(); } if (i == K*W) { V.push_back(Helper); j++; // This measures the j-th pseudosentence Helper.clear(); //for (int q=0; q < V.size(); ++q) { //cout << "Cluster "<< q << ": \n"; //for (int y=0; y < V[q].size(); ++y) // This works //cout << y <<": "<< V[q][y] << endl; //} Block* Blbl = new Block; Blbl->setData(V[j-1], V[j]); // When I have K pseudosentences, I have a block. cout << "B = " << Blbl->p[0][5]<< endl; Blbl->rankterms(); // Assigning scores to words in a block Blocks.push_back(*Blbl); i = 0; } }
The code compiles, but when I try to use the setData(a,b)
method from a block, Xcode takes me to stl_construct.h
and tells me that it received an EXC_BAD_ACCESS
signal.
The code I accept is this:
(The actual line that ::new(static_cast<void*>(__p)) _T1(__value);
allocates is ::new(static_cast<void*>(__p)) _T1(__value);
so I thought this was due to the new statement, but the debugger actually showed me that I can use a new block, which I cannot do is a new Block(a,b)
(with a parameter constructor) or setting data ... I find this inconvenient because in every documentation it says that the =
operator was overloaded for vectors, therefore this should not be a problem ... Sorry again for the stupidity of the question, but I can not find it. :-(
source share