473,387 Members | 1,942 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

Thread, parameter passing

I am tring to start a thread where I am passing info into thread. According
to MS documentation I must do this by creating a class for that thread. I
have done this but am getting a compiler error. The error is:

c:\T02010_NET_ora9\cgi-bin\programs\TimeReader\TimeReaderWinService.cpp(1 04):
error C2475: 'ThreadWithState::readerThread' : forming a pointer-to-member
requires explicit use of the address-of operator ('&') and a qualified name

When I try to place '&' in what I believe is proper place I get a syntax
error on illegal use of '&'
I did have this line working before I tried to move it to this new class
with parameters. Below I have example of non working line and working line:
NON WORKING:
readThread = new Thread (new ThreadStart(this,
tws->ThreadWithState::readerThread));

WORKING:
readThread = new Thread (new
ThreadStart(this,&TimeReaderWinService::readerThre ad));

Below is a little more complete listing of code so you can see I have
declared things:
public __gc class TimeReaderWinService : public
System::ServiceProcess::ServiceBase
{
private:
Thread *readThread;
void readerThread (void);
protected:
/// <summary>
/// Set things in motion so your service can do its work.
/// </summary>
void OnStart(String* args[]);
private:
};

public __gc class ThreadWithState {
public:
ThreadWithState (Queue *queue_ptr);
void readerThread (void);
int ParseEmpcode (StreamWriter *fip, String*& empcode, String *data, int
track,
int leadskip, int tailskip, char skipzero);

// State information used in the task
private:
Queue *mySyncdQ;
};

void TimeReaderWinService::OnStart(String* args[])
{
Queue *myQ,
*mySyncdQ;
Thread *readThread;

myQ = new Queue();
mySyncdQ = Queue::Synchronized(myQ);
ThreadWithState *tws = new ThreadWithState (mySyncdQ);

// TODO: Add code here to start your service.
// Start a separate thread that does actual reading
if((readThread == NULL) || (readThread->ThreadState &
(System::Threading::ThreadState::Unstarted |
System::Threading::Stopped)) !=
(System::Threading::ThreadState)0) {
//This is the line that is having the problem
readThread = new Thread (new ThreadStart(this,
tws->ThreadWithState::readerThread));

// readThread = new Thread (new
ThreadStart(this,&TimeReaderWinService::readerThre ad));
readThread->Start();
}

}
Dec 19 '05 #1
3 1798
brian_harris wrote:
I am tring to start a thread where I am passing info into thread.
According to MS documentation I must do this by creating a class for
that thread. I have done this but am getting a compiler error. The
error is:

c:\T02010_NET_ora9\cgi-bin\programs\TimeReader\TimeReaderWinService.cpp(1 04):
error C2475: 'ThreadWithState::readerThread' : forming a
pointer-to-member requires explicit use of the address-of operator
('&') and a qualified name


You need:

//This is the line that is having the problem
readThread = new Thread (new
ThreadStart(tws,&ThreadWithState::readerThread));

-cd
Dec 19 '05 #2
Thanks,
That got me past my compiler problem. Do you have an recomendations on
books for learning manged C++. I have microsoft visual C++ .NET step by step
version 2003. While it gave me a good introduction, it does not provide
enough information on what other classes are avaible and how to use them.
Microsofts online examples are so simplified I have not been able to easly
map them to real life usage. So I am looking for a more complete reference
to manged C++.

"Carl Daniel [VC++ MVP]" wrote:
brian_harris wrote:
I am tring to start a thread where I am passing info into thread.
According to MS documentation I must do this by creating a class for
that thread. I have done this but am getting a compiler error. The
error is:

c:\T02010_NET_ora9\cgi-bin\programs\TimeReader\TimeReaderWinService.cpp(1 04):
error C2475: 'ThreadWithState::readerThread' : forming a
pointer-to-member requires explicit use of the address-of operator
('&') and a qualified name


You need:

//This is the line that is having the problem
readThread = new Thread (new
ThreadStart(tws,&ThreadWithState::readerThread));

-cd

Dec 19 '05 #3
brian_harris wrote:
Thanks,
That got me past my compiler problem. Do you have an recomendations
on
books for learning manged C++. I have microsoft visual C++ .NET step
by step version 2003. While it gave me a good introduction, it does
not provide
enough information on what other classes are avaible and how to use
them. Microsofts online examples are so simplified I have not been
able to easly
map them to real life usage. So I am looking for a more complete
reference
to manged C++.


Actually, I'd recommend getting VC++ 2005 and switching to C++/CLI. It's
much more capable and plays better with the rest of the .NET framework.

For VC 7.1 managed C++, this book is usually well thought of:

http://www.amazon.com/gp/product/073...lance&n=283155

-cd
Dec 19 '05 #4

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

Similar topics

31
by: AlexeiOst | last post by:
Everywhere in documentation there are recommendations to use threads from thread pooling for relatively short tasks. As I understand, fetching a page or multiple pages (sometimes up to 50 but not...
2
by: Job Lot | last post by:
How can I pass parameters to a procedure which is called in thread? '! Spin off a new thread. myThread = New Thread(New ThreadStart(AddressOf GetRawFigures)) myThread.IsBackground = True...
2
by: Carlos | last post by:
Hi all, I am familiar with passing parameters to a thread function using C++, but I needt to learn it using C#. Can someone shed some light on how to do this? Code snippets will be great to show...
2
by: Claudio Biagioli | last post by:
I start a parallel thread inside a control with the following code: Private Sub StartParallelProc(ByVal Command As SqlClient.SqlCommand) Dim T As New Threading.Thread(AddressOf ParallelProc) ...
7
by: Charles Law | last post by:
My first thought was to call WorkerThread.Suspend but the help cautions against this (for good reason) because the caller has no control over where the thread actually stops, and it might have...
3
by: JohnnyGr | last post by:
I have heard theres a new way to start threads with parameters in framework 2.0, does anyone know how to do that? this is what i need to do... Start a thread that executes some stuff, in this...
3
by: kplkumar | last post by:
I want to call a method passing a parameter. I want to do this call on a seperate thread. For example, public class Foo { public static void FooSend(Message message) { // Start a seperate...
6
by: Sergey Poberezovskiy | last post by:
I have the following code in C# that I have trouble converting to VB(2.0): private delegate void openDialog(); private void openWindowsDialog(openDialog open) { Thread thread = new Thread(new...
2
by: JackC | last post by:
Hi, I create my threads like this: for(int j = 0; j < 5; j++) { boost::thread *thr = new boost::thread(worker_func); threads.add_thread(thr); }
8
by: asit | last post by:
How do I pass parameters to created thread..here is the code(but it can't pass data..it uses global variable) #include <windows.h> #include <stdio.h> DWORD Sum; DWORD WINAPI...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
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,...

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.