473,587 Members | 2,588 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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_STAR T_ROUTINE)watch dog,...);

}

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 2944
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
18199
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" contains something like "file:///C:/Documents%20and%20Settings/user/Desktop/Test/fileread.htm"
4
1890
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 tired of typing Dim MySQL As String every time I wanted to use it in a procedure for concatenating SQL needed for a RunSQL statement.
4
6638
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 potential problems for thread-safety. So far, I'm only confused. I need a proper explanation for the concept so I can understand how to write...
2
1355
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 string is initialized to odd characters and I cannot change the value. The following is the code I have to create the variable: private string...
4
405
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 connection string in memory variable ? I am thinking to add a member variable to Global class in global.aspx.cs and initialize it in...
1
1410
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 get a reference to an instance of my object courseObject - created using the following code. function...
18
1670
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
29333
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 called it polluting the global namespace. This article explores what happens when the global namespace becomes polluted and how to avoid this...
15
2350
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 finished I want to convert the array into a string which can be used by another function. My attempt to do this is not working. The script looks like...
0
7918
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
8206
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
8340
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7967
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
1
5713
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5392
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3840
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3875
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1185
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.