We help IT Professionals succeed at work.

warning C4290: C++ exception specification ignored except to indicate a function is not __declspec(nothrow)

racineconde
racineconde asked
on
Medium Priority
4,728 Views
Last Modified: 2012-05-05
Hi,
Here's the other warning I receive when I compile the source code.
//------------------------
warning C4290: C++ exception specification ignored except to indicate a function is not __declspec(nothrow)
//------------------------

The line incriminated is between two lines like this: //-------------------------------------------------------------------------

Here's all the code
//*************************** BEGINNING OF THE CODE
#ifndef cUnknownPtr_DEFINED
#define cUnknownPtr_DEFINED

template <typename T>
class cUnknownPtr
{
  T* ptr;
public:
  cUnknownPtr() : ptr(0)
  {
  }

  cUnknownPtr(T* p) : ptr(p)
  {
  }

  cUnknownPtr(const cUnknownPtr<T>& other) : ptr(other.ptr)
  {
    if(ptr)
    {
      ptr->AddRef();
    }
  }

  ~cUnknownPtr()
  {
    setNull();
  }

  cUnknownPtr<T>& operator = (const cUnknownPtr<T>& other) //treat as pointer
  {
    if(other.ptr != ptr)
    {
      if(ptr)ptr->Release();
      ptr = other.ptr;
      if(ptr)ptr->AddRef();
    }
    return *this;
  }

  T* operator -> () //treat as pointer
  {
    return ptr;
  }

  operator T* () //silent cast operator
  {
    return ptr;
  }

  T** operator & () //address of operator
  {
    return &ptr;
  }

  bool isValid()
  {
    return ptr != 0;
  }

  bool isNull()
  {
    return ptr == 0;
  }

  void setNull()
  {
    if(ptr)
    {
      ptr->Release();
      ptr = 0;
    }
  }

  bool QI(REFIID riid,void** ppObj)
  {
    if(isNull())return false;
    return SUCCEEDED(ptr->QueryInterface(riid,ppObj));
  }

//----------------------------------------------------------------------
void demandQI(REFIID riid,void** ppObj) throw(HRESULT)
//----------------------------------------------------------------------
  {
    if(isNull())throw E_FAIL;
    HRESULT hr = ptr->QueryInterface(riid,ppObj);
    if(FAILED(hr))
    {
      throw hr;
    }
  }
};

inline void checkResult(HRESULT r)
{
  if (FAILED(r))
    throw r;
}

#endif//cUnknownPtr_DEFINED
//*************************** END OF THE CODE

THANKS YOU FOR ANY ADVICE...
Comment
Watch Question

Commented:
C++ compiler allows this feature for future use, but doesn't implement it. throw(HRESULT) part is not implemented currently, as described in the C4290 MSDN topic. To turn off this warning add:

#pragma warning( disable : 4290 )

Not the solution you were looking for? Getting a personalized solution is easy.

Ask the Experts

Author

Commented:
I'm very impressed Alex... very impressed...
Access more of Experts Exchange with a free account
Thanks for using Experts Exchange.

Create a free account to continue.

Limited access with a free account allows you to:

  • View three pieces of content (articles, solutions, posts, and videos)
  • Ask the experts questions (counted toward content limit)
  • Customize your dashboard and profile

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.