"Sumit Rajan" <su*********@gm ail.com> wrote in message
news:3r******** ****@individual .net...
Could you please post some code that demonstates your problem? Please
remember to keep it minimal and compile-able:
http://www.parashift.com/c++-faq-lit...t.html#faq-5.8
I get error Unhandled exception at 0x00415329 in ClientTestClass es.exe:
0xC0000005: Access violation reading location 0x000002c4. It's something to
do with the way I'm filling and/or accessing the vector.
I need to get RequestCall() to return a call from the call_list vector.
/* Manager.cpp */
void Manager::Login( )
{
proxy.FillVecto rs(); /* fills the vector in ClientProxy */
proxy.RequestCa ll(current_camp aign); /* crash occurs in this method */
}
/* ClientProxy.h */
#ifndef __CLIENTPROXY__
#define __CLIENTPROXY__
#include "Call.h"
#include "Campaign.h "
#include "User.h"
#include "vector"
using namespace std;
class ClientProxy
{
public:
ClientProxy();
User Login(const std::string& sname, const std::string& ip, int pn);
Campaign RequestCampaign s(User u);
Call RequestCall(Cam paign c);
bool MarshallRequest ();
void FillVectors();
private:
/* Test variables below */
Call GetNextCall();
int call_counter;
/* Real vars */
Call current_call;
Campaign current_campaig n;
User user;
vector<Campaign > campaigns;
vector<Call> call_list;
};
/* END CLASS DEFINITION ClientProxy */
#endif
/* ClientProxy.cpp */
#include "ClientProx y.h"
#include "Call.h"
#include <vector>
ClientProxy::Cl ientProxy()
{
}
void ClientProxy::Fi llVectors()
{
printf("\n-FillVectors()") ;
vector<Campaign > campaigns(5);
campaigns[0] = Campaign(1, "Camp1");
campaigns[1] = Campaign(2, "Camp2");
campaigns[2] = Campaign(3, "Camp3");
campaigns[3] = Campaign(4, "Camp4");
campaigns[4] = Campaign(5, "Camp5");
vector<Call> call_list(5);
call_list[0] = Call(1,"0121575 5533","","Dave Jones","Jones
Construction"," 123 Main Street","",""," ");
call_list[1] = Call(2,"0121573 1432","","Steve Martin","Martin s
Butchers","10 West Street","",""," ");
call_list[2] = Call(3,"0131543 5467","","Phil Babb","BB Insurance","3 North
Street","",""," ");
call_list[3] = Call(4,"0141577 2234","","Tony Van Bronkel","GVK", "12 South
Street","",""," ");
call_list[4] = Call(5,"0151812 6534","","Steve Alabaster","MRM ","13 High
Street","",""," ");
call_counter = 0;
//printf(call_lis t[0].GetName().c_st r());
}
User ClientProxy::Lo gin(const std::string& sname, const std::string& ip, int
pn)
{
user.SetName(sn ame);
user.SetUserID( 1);
//call_list.inser t(sname);
return user;
}
Campaign ClientProxy::Re questCampaigns( User u)
{
return current_campaig n;
}
Call ClientProxy::Re questCall(Campa ign c)
{
//current_call = GetNextCall();
current_call = call_list[3]; /* ERROR BREAKS HERE */
printf("\n");
printf("-ClientProxy.Req uestCall()");
printf(current_ call.GetName(). c_str());
printf("-eof");
return current_call;
}
/* This is a temporary method to retrieve the contents of the call_list
vector */
Call ClientProxy::Ge tNextCall() {
Call ctemp = call_list[call_counter];
call_counter++;
return ctemp;
}
bool ClientProxy::Ma rshallRequest()
{
return 1;
}