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 6222387
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T08:18:17+00:00 2026-05-24T08:18:17+00:00

I have a strange issue with 2 arrays of pointer to pointer to objects

  • 0

I have a strange issue with 2 arrays of “pointer to pointer to objects” (by looking a te the code am i getting this right?)
I did read A LOT to try and grasp as much knowledge about what I’m trying to do but this error is getting overwhelming and I really wanna find out why is this happening.

For what I can see from the error that pops on this line:

vec_cliente[i] = new Cliente(nombre,apellido,carne,fecha); //this pops the error

is that I am trying to put the a new Cliente at vec_cliente[i] (0) and that doesn’t exist.

however… this

vec_solicitudes[i] = new Casa_Profesor(carne, fecha_sol, costo_mant, costo_alquiler, cant_p,salon); 

runs fine o.0

Principal.h has this:

#pragma once
#include string>
#include vector>
#include "Cliente.h"
#include "Persona.h"
#include "Casa_Profesor.h"
using namespace std;

class Principal{


private: 
    Cliente ** vec_cliente;
    Casa_Profesor ** vec_solicitudes;


public:
    static string  info [];
    static string  miembros [];

    Principal(void);
    void cargar(void);
    void calular_mayor_solicitudes(Cliente* vec_cliente, Casa_Profesor* vec_solicitudes);
    void mayor_costo(void);
    void ingreso_total(void);
    void espacio_mayor_uso(void);
    virtual ~Principal(void);

};

Principal.cpp has this:

#include "StdAfx.h"
#include "Principal.h"
#include iostream>
#include string>
#include sstream>
#include vector>
#include iterator>


using namespace std;

string Principal::info[] = {"623 25-05-2010 625.00 850.50 190 1"

                                ,"199 24-01-2009 300 900.5 180 1"
                ,"199 24-01-2010 300.50 900 175 2"
                ,"201 24-01-2009 300 900.5 180 3"
                ,"201 24-01-2010 300.50 900 175 3"
                ,"201 24-01-2009 30 900.5 180 3"
                ,"201 24-01-2010 300.50 900 175 3"
                ,"404 24-01-2009 300 900.5 180 3"
                ,"404 24-01-2010 300.50 900 175 2"
                ,"404 24-01-2009 30 900.5 180 3"
                ,"404 24-01-2010 300.50 900 175 2"
                ,"404 24-01-2009 300 90.5 180 3"
                ,"505 24-01-2010 300.50 900 175 2"
                ,"505 24-01-2009 300 900.5 180 3"
                ,"505 24-01-2010 300.50 900 175 2"
                ,"505 24-01-2009 300 90.5 180 1"
                ,"505 24-01-2010 300.50 900 175 1"
                ,"505 24-01-2009 300 900.5 180 3"
                ,"505 24-01-2010 1300.50 900 175 2"
                ,"106 24-01-2009 300 900.5 180 3"
                ,"106 24-01-2010 300.50 900 175 3"
                ,"106 24-01-2009 300 900.5 180 3"
                ,"106 24-01-2010 300.50 900 175 3"};


string Principal::miembros[] = {"Jaime Perez 623 22 12 1998"

                ,"Maria Perez 199 02 12 1988"
                ,"Jose Castro 201 3 11 2008"
                ,"Juan Caceres 404 21 1 2007"
                ,"Carla Vivas 505 18 09 1990"
                ,"Daniela Ochoa 106 02 01 2010"};

Principal::Principal(void)
{


}


void Principal::cargar(){

int i = 0, carne = 0, cant_p = 0, salon = 0;
string nombre, apellido, fecha, aux, fecha_sol;
double costo_mant, costo_alquiler;  

vec_solicitudes = new  Casa_Profesor * [(sizeof(info)/sizeof(string))*sizeof(Casa_Profesor)];

    for (i = 0; i < (sizeof(info)/sizeof(string)); i++){
        istringstream stream(info[i],ios_base::in);

        stream >> aux;
        carne = atoi(aux.c_str());
        stream >> fecha_sol;
        stream >> aux;
        costo_mant = atof(aux.c_str());
        stream >> aux;
        costo_alquiler = atof(aux.c_str());
        stream >> aux;
        cant_p = atoi(aux.c_str());
        stream >> aux;
        salon = atoi(aux.c_str());


        vec_solicitudes[i] = new Casa_Profesor(carne, fecha_sol, costo_mant, costo_alquiler, cant_p,salon);  //THIS runs fine 
    }

vec_cliente = new  Cliente * [(sizeof(miembros)/sizeof(string))*sizeof(Cliente)];

    for (i = 0; i < (sizeof(miembros)/sizeof(string)); i++){
        istringstream stream(miembros[i],ios_base::in);

        stream >> nombre;
        stream >> apellido;
        stream >> aux;
        carne = atoi(aux.c_str());
        stream >> fecha;
        fecha.append(" ");
        stream >> aux;
        fecha.append(aux);
        fecha.append(" ");
        stream >> aux;
        fecha.append(aux);

        vec_cliente[i] = new Cliente(nombre,apellido,carne,fecha);  //THIS trows the exception
    }

}

/* the only difference between Casa_Profesor and Cliente is that Cliente inherits from a class Persona and Casa_Profesor doesn’t.
as for why is this code so weird: it’s a practice for programing but feel free to point out any other programming mistakes I’m making in this code (specially on the sizeof stuff)
ALSO, I could edit and post all the code for the clases and all that but I wanted to first see if someoe could point me into an obvious newbie mistake I might be making…
thanks in advance for any help */

  • 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-24T08:18:17+00:00Added an answer on May 24, 2026 at 8:18 am

    I am not sure why you get “vector subscript out of range” when you aren’t using any vectors, just raw pointers and arrays. I’ll assume that you didn’t tell us something!

    So I’ll just make some random comments on your code:

    vec_solicitudes = new  Casa_Profesor * [(sizeof(info)/sizeof(string))*sizeof(Casa_Profesor)];
    

    Are you trying to create 1 Casa_Profesor * in vec_solicitudes for each string in info? If so, you want:

    vec_solicitudes = new  Casa_Profesor * [sizeof(info)/sizeof(string)];
    

    This will allocate enough memory for (sizeof(info)/sizeof(string)) (Casa_Profesor *).

    Likewise:

    vec_cliente = new  Cliente * [sizeof(miembros)/sizeof(string)];
    

    However, your allocations are too big, rather than too small, so they are not the cause of the exception. I suggest instead that you look at the Casa_Profesor and Cliente constructors – they are where the exception probably originates.

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

Sidebar

Related Questions

I have a strange issue: When I scroll vertically it triggers swipe right/left events.
I have a strange issue with jQuery's hover, addClass $(document).ready(function(){ $('#selectable li').hover( function(){ $(this).addClass('selecting',
I have this strange issue that my git push origin master and cap deploy
Strange Issue. I have the some code that queries a database and prases the
I have this strange issue. When I run application from Xcode (even on device),
I'm having this strange issue where I have an NSArrayController bound to a managedObjectContext
I have this strange issue where anytime I open a XAML file that contains
I have a strange issue with a MVC 3 app running as an Azure
I have a strange issue . I am currently working on a mail app
i have a strange issue with phpexcel on a pair of formulas and can't

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.