944,137 Members | Top Members by Rank

Ad:
  • C++ Discussion Thread
  • Unsolved
  • Views: 382
  • C++ RSS
Oct 15th, 2009
0

Can't get strings to work...

Expand Post »
I want to use the string class in my program but I keep getting the following errors:

process.cpp:10: error: 'string' has not been declared
process.cpp:10: error: prototype for 'Process:: Process(int, int, int)'
does not match any in class 'Process'
process.h:14: error: candidates are: Process:: Process(const Process&)
process.h:16: error: Process:: Process(int, char*, int)
process.cpp: In constructor 'Process:: Process(int, int, int)':
process.cpp:14: error: invalid conversion from 'intâ to âchar*'
make: *** [process.o] Error 1

I don't understand why I'm getting this since my code doesn't seem to differ from the examples I found in tutorials too much:

C++ Syntax (Toggle Plain Text)
  1. /*
  2.  * process.h
  3.  *
  4.  * Created on: Oct 13, 2009
  5.  * Author: NTUser1
  6.  */
  7.  
  8. #ifndef PROCESS_H_
  9. #define PROCESS_H_
  10.  
  11. #include "thread.h"
  12.  
  13. #include <string>
  14. #include <iostream>
  15.  
  16. using namespace std;
  17.  
  18. class Process : public Thread
  19. {
  20. public:
  21. Process(int at, string process, int bt);
  22.  
  23. int arrivalTime; // arrival time of a process
  24. string name; // process name, e.g., P0, P1, P2
  25. int burstTime; // CPU burst time of a process
  26. int remainTime; // the remaining burst time of a process
  27.  
  28. void run();
  29.  
  30. private:
  31.  
  32. };

C++ Syntax (Toggle Plain Text)
  1. /*
  2.  * process.cpp
  3.  *
  4.  * Created on: Oct 13, 2009
  5.  * Author: NTUser1
  6.  */
  7.  
  8. #include "process.h"
  9.  
  10. Process::Process(int at, string process, int bt){
  11.  
  12. arrivalTime = at;
  13. burstTime = bt; //etc for the rest of the vars
  14. name = process;
  15. }
  16.  
  17. void Process::run(){
  18. state = RUNNING;
  19. sleep(burstTime);
  20. stop();
  21. }
Last edited by pocku; Oct 15th, 2009 at 9:11 pm.
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
pocku is offline Offline
22 posts
since Nov 2007
Oct 16th, 2009
-7
Re: Can't get strings to work...
what compiler/version are you using ?
Sponsor
Team Colleague
Featured Poster
Reputation Points: 5608
Solved Threads: 2283
Retired and Enjoying Life
Ancient Dragon is offline Offline
21,963 posts
since Aug 2005
Oct 16th, 2009
0
Re: Can't get strings to work...
I'm not sure which thread library you are using, but even without it you are missing an #endif at the end of your header. I'm not sure if that's the main issue. Are there other errors besides the ones you pasted in?
Sponsor
Featured Poster
Reputation Points: 1165
Solved Threads: 578
Quantitative Phrenologist
jonsca is offline Offline
4,271 posts
since Sep 2009
Oct 16th, 2009
0
Re: Can't get strings to work...
Click to Expand / Collapse  Quote originally posted by jonsca ...
I'm not sure which thread library you are using, but even without it you are missing an #endif at the end of your header. I'm not sure if that's the main issue. Are there other errors besides the ones you pasted in?
I'm using pthread but no, I just forgot to paste in the #endif, it's there in my code. The errors I've posted are the only the ones I'm getting...

what compiler/version are you using ?
Not too sure as I am doing this on a university computer and I don't know where I can go check at this time.
Last edited by pocku; Oct 16th, 2009 at 12:43 am.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
pocku is offline Offline
22 posts
since Nov 2007
Oct 16th, 2009
-7
Re: Can't get strings to work...
what is the command line to compile something? Or are you using an IDE? Do you know what operating system (e.g. *nix or MS-Windows)?
Sponsor
Team Colleague
Featured Poster
Reputation Points: 5608
Solved Threads: 2283
Retired and Enjoying Life
Ancient Dragon is offline Offline
21,963 posts
since Aug 2005
Oct 16th, 2009
0
Re: Can't get strings to work...
what is the command line to compile something? Or are you using an IDE? Do you know what operating system (e.g. *nix or MS-Windows)?
I use either g++ or make (to compile multiple files together). I'm programming this on a terminal on linux.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
pocku is offline Offline
22 posts
since Nov 2007

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C++ Forum Timeline: How to extract a row of a 2d Vector
Next Thread in C++ Forum Timeline: Simple Linked List: crashes





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC