Go Back   TechArena Community > Software > Software Development
Become a Member!
Forgot your username/password?
Tags Active Topics RSS Search Mark Forums Read

Reply
 
Thread Tools Search this Thread
  #1  
Old 14-05-2009
Member
 
Join Date: May 2008
Posts: 2,442
Problem reading deque pointers on objects

I have used double-ended queue in my program. But I noticed that only the last elements gets introduced.

Here is my own class (I use "CustomRequest" to complete and "DisplayRequest" for display):

Code:
  #include <iostream> 
  #include <fstream> 
  #include <string.h> 
  #include "Class.h" 
  using namespace std; 
  unsigned long Request:: counter = 0L; 

  Request:: Request() // Constructor
  {
	  id = ++counter; 
	  pnom = new char [MAXLEN_NAME 1]; 
	  memset (pnom, 0, MAXLEN_NAME 1);
	  health = 100; 
	  exp = 0; 
	  class = 0; 
  }
  About Me:: ~ Request(void) // Destructor 
  {
	  delete [] pnom; 
  }

  Request:: Request(Request &source) 
  {
	  if (this == &source) return; 
	  pnom = new char [MAXLEN_NAME 1]; 
	  strcpy (pnom source. pnom); 
	  exp = source. exp; 
	  counter = source. counter; 
	  Health = source. Health; 
	  class = source. Class; 
  }
  Request &Request:: operator = (Request &source) 
  {
	  if (this == &source) return (*this); 
	  strcpy (pnom source. pnom); 
	  Exp = source. Exp; 
	  counter = source. counter; 
	  Health = source. Health; 
	  class = source. Class; 
	  return (* this); 
  }
  void Request:: DisplayRequest(Request *aRequest) 
  {
	  cout << "Name:" <<pnom <<endl; 
	  cout << "Experience:" <<exp <<endl; 
	  cout << "ID:" <<id <<endl; 
	  cout << "health" <<health <<endl; 
	  cout << "Class:" <<grade <<endl; 
	  cout << "Force:" <<power <<endl; 
	  cout << "Agility:" <<AGILITY <<endl; 
	  cout << "Intelligence:" <<Intell <<endl; 
	  cout <<"----------------------------------------" <<endl; 
  }
  void Request:: CustomRequest (Request *aRequest) 
  { 
	  int buflen = aRequest-> MAXLEN_NAME; 
	  cout << "Creation" <<endl <<endl; 
	  cout << "Name:"; 
	  cin. ignore ();
	  cin. getline (aRequest-> pnom, buflen); 
	  aRequest-> pnom [buflen +1]; 
	  cout << "Enter power:"; 
	  cin>> force; 
	  cout << "Enter Agility:"; 
	  cin>> AGILITY; 
	  cout << "Enter Intelligence"; 
	  cin>> Intel; 
  }
Here is my main:

Code:
  #include "Class.h" 
  #include <deque> 
  using namespace std; 
  void main () 
  {
	  Request* ptrav = NULL; 
	  ptrav=new Request;
	  DEQUE <Request*> dprequest; 
	  DEQUE <Request*>:: iterator IPB 
        ptrav-> CustomRequest (ptrav);
	  dprequest. push_back (ptrav); 
	  ptrav-> CustomRequest (ptrav); 
	  dprequest. push_back (ptrav); 
	  System ( "cls"); 
	  for (IPB = dprequest. begin (); IPB! = dprequest. end (); IPB + +) 
	  { 
		  ptrav-> DisplayRequest(IPB *); 
	  } 
	  cout << "the DEQUE a" <<dprequest. size () << "elements" <<endl; 
	  System ( "pause"); 
  }
Reply With Quote
  #2  
Old 14-05-2009
Member
 
Join Date: May 2008
Posts: 685
Re: Problem reading deque pointers on objects

Your code seem to me a very complicated one. I would rather use a member function show() in class Request. And then code in this way:

Code:
  for (ipb = dprequest.begin (); ipb!= dprequest.end (); ipb++)  
  {
	  ipb-> show(); 
  }
Reply With Quote
  #3  
Old 14-05-2009
Member
 
Join Date: Jan 2008
Posts: 1,515
Re: Problem reading deque pointers on objects

DisplayRequest and CustomRequest applies on a personal object (they are clearly not static) and takes as parameter a pointer to own? It needs little reading/modification of members of the object and the parameters. Finally, why are you using a char* for your string and not std::string?
Reply With Quote
Reply

  TechArena Community > Software > Software Development
Tags: , ,



Thread Tools Search this Thread
Search this Thread:

Advanced Search


Similar Threads for: "Problem reading deque pointers on objects"
Thread Thread Starter Forum Replies Last Post
There was a problem reading this document (14) Paramartha Software Development 4 11-01-2011 06:43 PM
problem in Reading XML via LINQ Steadfast Software Development 5 12-02-2010 08:29 PM
Problem in reading stream Windowed Windows Software 5 06-01-2010 11:15 AM
Problem reading C++ matrix killerboy Software Development 4 14-11-2009 05:07 PM
Problem reading USB stick - Empty Shell - Portable Devices 3 05-02-2009 08:25 PM


All times are GMT +5.5. The time now is 01:45 AM.