472,799 Members | 1,684 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,799 software developers and data experts.

C++ string global variable

I am pretty new to using C++ and I can't figure this out.

I have class PTM that starts a thread. There is an array of structure
to be shared between PTM class and thread function. For some reason,
string data gets lost when it gets to the thread function.

----------
in PTM.h
----------
using namespace std;

struct process_list{
string title;
int status;
int num_restart;
string comments;
};
-----------
in PTM.cpp
-----------
process_list global_process[10];
int process_num ;

PTM::PTM(){
loadConfig()
CreateThread(...,LPTHREAD_START_ROUTINE)watchdog,. ..);

}

PTM::loadConfig() {
for (int i =0; i < condition; i++) {
global_process[i].title= "gets data";
global_process[i].status = 0;
}
process_num = i;
}

//global function in the file scope watchdog
int watchdog() {
//print the global variables
for (int j =0 ; j < process_num; j++) {
printLog("%s has died", global_process[i].title;
}

}

I ran it thru debugger. It seems like watchdog() sees process_num(int
type) global variable. It also sees status, num_restart in
globa_process but not title or comment which are string type.
loadConfig seems to work fine too.

Any ideas, comments, help will be greatly appreciate.

Thanks in advance,

Seung

Jul 23 '05 #1
2 2893
On 9 Feb 2005 23:16:09 -0800 in comp.lang.c++, "semi"
<mi*****@yahoo.com> wrote,
I am pretty new to using C++ and I can't figure this out.

I have class PTM that starts a thread. There is an array of structure
to be shared between PTM class and thread function. For some reason,
string data gets lost when it gets to the thread function.

----------
in PTM.h
----------
using namespace std;
Bad form, forcing a "using namespace" on all the possible includers of
your header.

....
struct process_list{
string title;
for (int j =0 ; j < process_num; j++) {
printLog("%s has died", global_process[i].title;


I don't see your definition of printLog, but I venture to guess that
it knows nothing of std::string. Perhaps it would be happier with
global_process[i].title.c_str()

How did you compile with unmatching parenthesis?

Jul 23 '05 #2
Obviously it is not the exact code I have.
It was a pseudo coded to be posted. My printLog does what c_str()
does.

Thanks for pointing out the namespace use in .h
David Harmon wrote:
On 9 Feb 2005 23:16:09 -0800 in comp.lang.c++, "semi"
<mi*****@yahoo.com> wrote,
I am pretty new to using C++ and I can't figure this out.

I have class PTM that starts a thread. There is an array of structureto be shared between PTM class and thread function. For some reason,string data gets lost when it gets to the thread function.

----------
in PTM.h
----------
using namespace std;
Bad form, forcing a "using namespace" on all the possible includers

of your header.

...
struct process_list{
string title;
for (int j =0 ; j < process_num; j++) {
printLog("%s has died", global_process[i].title;


I don't see your definition of printLog, but I venture to guess that
it knows nothing of std::string. Perhaps it would be happier with
global_process[i].title.c_str()

How did you compile with unmatching parenthesis?


Jul 23 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Phrederik | last post by:
Hey all! New to javascript and still getting my head around strings... Consider the following line of code... var path = location.pathname; ....after execution, the variable "path"...
4
by: MLH | last post by:
I have a module named Declarations. In it, there is a line that reads: Global MySQL As String I decided to dimension it as a global variable after I was already deep into development. I got...
4
by: Jonathan Burd | last post by:
Greetings everyone, Here is a random string generator I wrote for an application and I'm wondering about the thread-safety of this function. I was told using static and global variables cause...
2
by: Elizabeth Graham | last post by:
I am creating a global string variable in the beginning of my code. I am setting the string to an empty value. I am running the component in debug mode and when I step through the component, the...
4
by: A.M | last post by:
Hi, I have an encrypted database connection string stored in web.config file and i need to have the connection string several times in my application. What would be the best way to have that...
1
by: andy_w_irvine | last post by:
Hi, Apologies if this has been asked elsewhere, I did search but expect I didn't hit on the required terminology. I want to be able to use a string variable called objectName (original!) to...
18
by: greenflame | last post by:
I want to make a function that does the following. I will call it thefunc for short. '||Char>>' I tried the following def thefunc(s): s = "||" + s + ">>"
1
weaknessforcats
by: weaknessforcats | last post by:
C++: The Case Against Global Variables Summary This article explores the negative ramifications of using global variables. The use of global variables is such a problem that C++ architects have...
15
by: Steve | last post by:
I am having problems getting values out of an array. The array is set as a global array and values are pushed into it as they are read from a JSON file using a "for loop". When the "for loop" is...
3
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 2 August 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
by: kcodez | last post by:
As a H5 game development enthusiast, I recently wrote a very interesting little game - Toy Claw ((http://claw.kjeek.com/))。Here I will summarize and share the development experience here, and hope it...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Sept 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
14
DJRhino1175
by: DJRhino1175 | last post by:
When I run this code I get an error, its Run-time error# 424 Object required...This is my first attempt at doing something like this. I test the entire code and it worked until I added this - If...
5
by: DJRhino | last post by:
Private Sub CboDrawingID_BeforeUpdate(Cancel As Integer) If = 310029923 Or 310030138 Or 310030152 Or 310030346 Or 310030348 Or _ 310030356 Or 310030359 Or 310030362 Or...
0
by: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
0
by: lllomh | last post by:
How does React native implement an English player?
0
by: Mushico | last post by:
How to calculate date of retirement from date of birth
2
by: DJRhino | last post by:
Was curious if anyone else was having this same issue or not.... I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.