Thread, parameter passing

G

Guest

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(104):
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::readerThread));

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::readerThread));
readThread->Start();
}

}
 
C

Carl Daniel [VC++ MVP]

brian_harris said:
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(104):
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
 
G

Guest

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++.
 
C

Carl Daniel [VC++ MVP]

brian_harris said:
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/07...102-0715472-9505747?s=books&v=glance&n=283155

-cd
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top