描述:
#include "interface.h"
#include "math.h"
STDMETHODIMP CMath::QueryInterface(REFIID riid, void **ppv)
{// ÕâÀïÕâÊÇʵÏÖdynamic_castµÄ¹¦ÄÜ£¬µ«ÓÉÓÚdynamic_castÓë±àÒëÆ÷Ïà¹Ø¡£
if(riid == IID_ISimpleMath)
*ppv = static_cast(this);
else if(riid == IID_IAdvancedMath)
*ppv = static_cast(this);
else if(riid == IID_IUnknown)
*ppv = static_cast(this);
else {
*ppv = 0;
return E_NOINTERFACE;
}
reinterpret_cast(*ppv)->AddRef(); //ÕâÀïÒªÕâÑùÊÇÒòΪÒýÓüÆÊýÊÇÕë¶Ô×é¼þµÄ
return S_OK;
}
STDMETHODIMP_(ULONG) CMath::AddRef()
{
return ++m_cRef;
}
STDMETHODIMP_(ULONG) CMath::Release()
{
ULONG res = --m_cRef; // ʹÓÃÁÙʱ±äÁ¿°ÑÐ޸ĺóµÄÒýÓüÆÊýÖµ»º´æÆðÀ´
if(res == 0) // ÒòΪÔÚ¶ÔÏóÒѾ­Ïú»ÙºóÔÙÒýÓÃÕâ¸ö¶ÔÏóµÄÊý¾Ý½«ÊÇ·Ç·¨µÄ
delete this;
return res;
}
int CMath::Add(int nOp1, int nOp2)
{
return nOp1+nOp2;
}
int CMath::Subtract(int nOp1, int nOp2)
{
return nOp1 - nOp2;
}
int CMath::Multiply(int nOp1, int nOp2)
{
return nOp1 * nOp2;
}
int CMath::Divide(int nOp1, int nOp2)
{
return nOp1 / nOp2;
}
int CMath::calcFactorial(int nOp)
{
if(nOp <= 1)
return 1;
return nOp * calcFactorial(nOp - 1);
}
int CMath::Factorial(int nOp)
{
return calcFactorial(nOp);
}
int CMath::calcFabonacci(int nOp)
{
if(nOp <= 1)
return 1;
return calcFabonacci(nOp - 1) + calcFabonacci(nOp - 2);
}
int CMath::Fabonacci(int nOp)
{
return calcFabonacci(nOp);
}
CMath::CMath()
{
m_cRef=0;
}
上面的程序编译时有问题.
出错如下:
--------------------Configuration: xCom - Win32 Debug--------------------
Compiling...
math.cpp
D:\GOOD\xCom\math.cpp(7) : error C2059: syntax error : '('
D:\GOOD\xCom\math.cpp(9) : error C2059: syntax error : '('
D:\GOOD\xCom\math.cpp(11) : error C2059: syntax error : '('
D:\GOOD\xCom\math.cpp(17) : error C2059: syntax error : '('
D:\GOOD\xCom\math.cpp(80) : error C2084: function '__thiscall CMath::CMath(void)' already has a body
Error executing cl.exe.
math.obj - 5 error(s), 0 warning(s)