H
hyd
Hello,
I use VS2005 - C++/CLI.
I have some kind of events in native C++. I want to raise .NET events
when my native C++ events occur.
So, I wrote some code for that but I have an C1001 error (An internal
error has occurred in the compiler).
Below, a piece of code that produces the same error :
***** CLR - Class Library project *****
--- Mixed.cpp ---
struct Handler
{
virtual void Call( int iI, double iD ) = 0;
};
template<class T, void (T::*TMethod)( int, double )>
struct THandler : public Handler
{
T* pT;
THandler( T* ipT )
{
pT = ipT;
}
virtual void Call( int iI, double iD )
{
(pT->*TMethod)( iI, iD );
}
};
class Event
{
Handler* pHandler;
public:
Event() : pHandler(0) {}
template<class T, void (T::*TMethod)( int, double )>
void Register( T* ipT )
{
if( pHandler ) delete pHandler;
pHandler = new THandler<T, TMethod>( ipT );
}
void Raise( int iI, double iD )
{
if( pHandler ) pHandler->Call( iI, iD );
}
};
class Foo
{
public:
Event MyEvent;
Foo(void) {}
virtual ~Foo(void) {}
void DoSomething()
{
MyEvent.Raise( 1, 2.3 );
MyEvent.Raise( 5, 8.4 );
MyEvent.Raise( 4, 4.2 );
}
};
class UseFoo
{
public:
Foo* pFoo;
UseFoo()
{
pFoo = new Foo();
pFoo->MyEvent.Register<UseFoo, &UseFoo::OnMyEvent>( this );
}
void OnMyEvent( int iI, double iD )
{
double d = iI * iD;
}
};
public ref class MUseFoo
{
internal:
UseFoo* pUseFoo;
public:
MUseFoo()
{
pUseFoo = new UseFoo();
}
virtual ~MUseFoo()
{
delete pUseFoo;
}
};
****************************************************
The compilation gives me the following error :
1>Managed.cpp
1>.\Managed.cpp(19) : fatal error C1001: An internal error has occurred
in the compiler.
1>(compiler file 'msc1.cpp', line 1392)
1> To work around this problem, try simplifying or changing the program
near the locations listed above.
1>Please choose the Technical Support command on the Visual C++
1> Help menu, or open the Technical Support help file for more
information
1> .\Managed.cpp(18) : while compiling class template member
function 'void THandler<T,TMethod>::Call(int,double)'
1> with
1> [
1> T=UseFoo,
1> TMethod={&UseFoo::OnMyEvent,0}
1> ]
1> .\Managed.cpp(33) : see reference to class template
instantiation 'THandler<T,TMethod>' being compiled
1> with
1> [
1> T=UseFoo,
1> TMethod={&UseFoo::OnMyEvent,0}
1> ]
1> .\Managed.cpp(66) : see reference to function template
instantiation 'void Event::Register<UseFoo,{&UseFoo::OnMyEvent,0}>(T
*)' being compiled
1> with
1> [
1> T=UseFoo
1> ]
Without the MUseFoo class, the project compiles fine.
Anybody would have an idea about this problem ???
Thanks,
Hervé.
I use VS2005 - C++/CLI.
I have some kind of events in native C++. I want to raise .NET events
when my native C++ events occur.
So, I wrote some code for that but I have an C1001 error (An internal
error has occurred in the compiler).
Below, a piece of code that produces the same error :
***** CLR - Class Library project *****
--- Mixed.cpp ---
struct Handler
{
virtual void Call( int iI, double iD ) = 0;
};
template<class T, void (T::*TMethod)( int, double )>
struct THandler : public Handler
{
T* pT;
THandler( T* ipT )
{
pT = ipT;
}
virtual void Call( int iI, double iD )
{
(pT->*TMethod)( iI, iD );
}
};
class Event
{
Handler* pHandler;
public:
Event() : pHandler(0) {}
template<class T, void (T::*TMethod)( int, double )>
void Register( T* ipT )
{
if( pHandler ) delete pHandler;
pHandler = new THandler<T, TMethod>( ipT );
}
void Raise( int iI, double iD )
{
if( pHandler ) pHandler->Call( iI, iD );
}
};
class Foo
{
public:
Event MyEvent;
Foo(void) {}
virtual ~Foo(void) {}
void DoSomething()
{
MyEvent.Raise( 1, 2.3 );
MyEvent.Raise( 5, 8.4 );
MyEvent.Raise( 4, 4.2 );
}
};
class UseFoo
{
public:
Foo* pFoo;
UseFoo()
{
pFoo = new Foo();
pFoo->MyEvent.Register<UseFoo, &UseFoo::OnMyEvent>( this );
}
void OnMyEvent( int iI, double iD )
{
double d = iI * iD;
}
};
public ref class MUseFoo
{
internal:
UseFoo* pUseFoo;
public:
MUseFoo()
{
pUseFoo = new UseFoo();
}
virtual ~MUseFoo()
{
delete pUseFoo;
}
};
****************************************************
The compilation gives me the following error :
1>Managed.cpp
1>.\Managed.cpp(19) : fatal error C1001: An internal error has occurred
in the compiler.
1>(compiler file 'msc1.cpp', line 1392)
1> To work around this problem, try simplifying or changing the program
near the locations listed above.
1>Please choose the Technical Support command on the Visual C++
1> Help menu, or open the Technical Support help file for more
information
1> .\Managed.cpp(18) : while compiling class template member
function 'void THandler<T,TMethod>::Call(int,double)'
1> with
1> [
1> T=UseFoo,
1> TMethod={&UseFoo::OnMyEvent,0}
1> ]
1> .\Managed.cpp(33) : see reference to class template
instantiation 'THandler<T,TMethod>' being compiled
1> with
1> [
1> T=UseFoo,
1> TMethod={&UseFoo::OnMyEvent,0}
1> ]
1> .\Managed.cpp(66) : see reference to function template
instantiation 'void Event::Register<UseFoo,{&UseFoo::OnMyEvent,0}>(T
*)' being compiled
1> with
1> [
1> T=UseFoo
1> ]
Without the MUseFoo class, the project compiles fine.
Anybody would have an idea about this problem ???
Thanks,
Hervé.