Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6871109
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T03:45:54+00:00 2026-05-27T03:45:54+00:00

This question should be quite straightforward, maybe stupid but I just can’t find the

  • 0

This question should be quite straightforward, 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”. A Block is made of 2 Pseudosentences, which are made of 20 words (strings).

Here’s 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 Block, XCode takes me to stl_construct.h and tells me that he received a EXC_BAD_ACCESS signal.

The code to which I am taken is this:

/** @file stl_construct.h
*  This is an internal header file, included by other library headers.
*  You should not attempt to use it directly.
*/

#ifndef _STL_CONSTRUCT_H
#define _STL_CONSTRUCT_H 1

#include <bits/cpp_type_traits.h>
#include <new>

_GLIBCXX_BEGIN_NAMESPACE(std)

  /**
   * @if maint
   * Constructs an object in existing memory by invoking an allocated
   * object's constructor with an initializer.
   * @endif
   */
  template<typename _T1, typename _T2>
    inline void
    _Construct(_T1* __p, const _T2& __value)
    {
      // _GLIBCXX_RESOLVE_LIB_DEFECTS
      // 402. wrong new expression in [some_]allocator::construct
      ::new(static_cast<void*>(__p)) _T1(__value);
    }

(The actual line that XCode highlights is the ::new(static_cast<void*>(__p)) _T1(__value); so I thought it was due to the new operator, but in fact the debugger showed me that I can use a new Block; What I can’t do is a new Block(a,b) (with the parameter constructor) or setting data… I find this awkward, because every documentation says that the = operator has been overloaded for vectors, so it should be no problem… Sorry again for the stupid question, but I can’t find it. 🙁

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T03:45:55+00:00Added an answer on May 27, 2026 at 3:45 am

    Every time you add an element to V you also increment j. This means that j will always equal the length of V.

    That means that the below line will always result in access 1 past the end of V.

    Blbl->setData(V[j-1], V[j]);
    

    Using that value later (when it it part of a Block‘s p vector will result in all manner of potential problems. This is likely the source of your issue.

    Also, you have a memory leak (you newed but didn’t delete). Use a scoped_ptr here, or just create the value on the stack. There doesn’t seem to be a reason to allocate it on the heap.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This question should be quite clear from its title alone, but let me explain
I asked this question over Security site, and people there suggested I should have
I'm not 100% sure how I should word this question but I'll try my
I don't know which title I should use for this question. I have a
Dear all,Now i have this question in my java program,I think it should be
I'm not quite sure how to go about framing this question, but I am
This is quite straightforward: I have three tables: Questions: ID (PK) Body QuestionsAndAnswers: QuesionID
This question is about a general technique in SQL, that I can't quite work
I know this question has been asked quite a few times, however, I have
I have a case similar to this MySQL question regarding the IN clause, but

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.