I
Ian
I've just discovered the msclr::lock class in the C++ Support Library online
documentation. This seems like a much cleaner way to implement thread
protection than using monitor::enter/try/finally/monitor exit. However, I
cannot get around one of the warning messages and am requesting help in
understanding what is causing the warning.
All of the online sample code for the class msclr::lock generates the same
warning message. I have provide simplified code below that generates the
same warning message. The problem appears to be related to the typedef
'is_not' in the msclr::lock constructor. Can anyone help me out and explain
why this warning is occurring and how to work around it. I have limited
working experience with templates and this is the first time I've come
across a case where the class constructors are declared as templates but the
class isself is not. Can anyone explain what the warning means and what I
must do to avoid this warning message? I am working with VS2005, WinXP Pro
(SP2) and have the compiler warning level is set to 3.
Thanks for any and all help
Ian
SAMPLE CODE THAT GENERATES THE WARNING MESSAGE
================================================
#include "stdafx.h"
#include <msclr/lock.h>
using namespace System;
int main()
{
Object ^pObject = gcnew Object();
msclr::lock oL( pObject );
}
COMPILER WARNING MESSAGE
==========================
C:\Program Files\Microsoft Visual Studio 8\VC\include\msclr/lock.h(51) :
warning C4091: '' : ignored on left of 'int' when no variable is declared
..\testCPPConsoleApplication.cpp(12) : see reference to function template
instantiation 'msclr::lock::lock<System::Object>(T ^)' being compiled
with
[
T=System::Object
]
PARTS IN CLASS 'MSCLR::LOCK' THAT PRODUCE THE WARNING
===============================================
namespace msclr
{
ref class lock
{
private:
System::Object ^ m_object;
bool m_locked;
template<class T,class U> value struct is_not { typedef int
__dont_use_this_type__; };
public:
template<class T> lock( T ^ _object)
: m_object( _object ),
m_locked( false )
{
// ensure that T is not a ReaderWriterLock.
is_not<T,
System::Threading::ReaderWriterLock>::__dont_use_this_type__;
acquire(System::Threading::Timeout::Infinite);
}
... remainder of class definition...
};
documentation. This seems like a much cleaner way to implement thread
protection than using monitor::enter/try/finally/monitor exit. However, I
cannot get around one of the warning messages and am requesting help in
understanding what is causing the warning.
All of the online sample code for the class msclr::lock generates the same
warning message. I have provide simplified code below that generates the
same warning message. The problem appears to be related to the typedef
'is_not' in the msclr::lock constructor. Can anyone help me out and explain
why this warning is occurring and how to work around it. I have limited
working experience with templates and this is the first time I've come
across a case where the class constructors are declared as templates but the
class isself is not. Can anyone explain what the warning means and what I
must do to avoid this warning message? I am working with VS2005, WinXP Pro
(SP2) and have the compiler warning level is set to 3.
Thanks for any and all help
Ian
SAMPLE CODE THAT GENERATES THE WARNING MESSAGE
================================================
#include "stdafx.h"
#include <msclr/lock.h>
using namespace System;
int main()
{
Object ^pObject = gcnew Object();
msclr::lock oL( pObject );
}
COMPILER WARNING MESSAGE
==========================
C:\Program Files\Microsoft Visual Studio 8\VC\include\msclr/lock.h(51) :
warning C4091: '' : ignored on left of 'int' when no variable is declared
..\testCPPConsoleApplication.cpp(12) : see reference to function template
instantiation 'msclr::lock::lock<System::Object>(T ^)' being compiled
with
[
T=System::Object
]
PARTS IN CLASS 'MSCLR::LOCK' THAT PRODUCE THE WARNING
===============================================
namespace msclr
{
ref class lock
{
private:
System::Object ^ m_object;
bool m_locked;
template<class T,class U> value struct is_not { typedef int
__dont_use_this_type__; };
public:
template<class T> lock( T ^ _object)
: m_object( _object ),
m_locked( false )
{
// ensure that T is not a ReaderWriterLock.
is_not<T,
System::Threading::ReaderWriterLock>::__dont_use_this_type__;
acquire(System::Threading::Timeout::Infinite);
}
... remainder of class definition...
};