Anything and everything that's related to OGRE or the wider graphics field that doesn't fit into the other forums.
-
longer
- Kobold
- Posts: 37
- Joined: Tue Aug 19, 2014 10:46 am
- x 5
Post
by longer »
use dummy member function can do this.
Code: Select all
struct Tester
{
Tester(int) {} // No default constructor
void dummy() {}
};
typedef void (Tester::*unspecified_bool_type)();
operator unspecified_bool_type() const
{
return pRep == 0 ? 0 : &Tester::dummy;
}
//static void unspecified_bool( SharedPtr*** )
//{
//}
//typedef void (*unspecified_bool_type)( SharedPtr*** );
//operator unspecified_bool_type() const
//{
// return pRep == 0 ? 0 : &unspecified_bool;
//}
Ogre::SharedPtr a(new int);
// here not warning at msvc.
if(a)
{
// a is not empty.
}
-
Ybalrid
- Halfling
- Posts: 89
- Joined: Thu Jul 10, 2014 6:52 pm
- Location: France
- x 31
Post
by Ybalrid »
Isn't this expected behavior?
It's standard practice in C/C++ to test pointers if they are "NULL" or not.
if(pointer) is equivalent to testing if(pointer != 0). (NULL is a #define that has the value 0)
You'll get the same result with the C++ standard std::shared_ptr<> (available since C++11,) or the one from boost.
-
paroj
- OGRE Team Member

- Posts: 2141
- Joined: Sun Mar 30, 2014 2:51 pm
- x 1151
Post
by paroj »
-
Ybalrid
- Halfling
- Posts: 89
- Joined: Thu Jul 10, 2014 6:52 pm
- Location: France
- x 31
Post
by Ybalrid »
Oh, stupid indeed. I didn't even catch this was the actual problem discussed by the OP.
Speaking of stupid :
Casting the expression to type bool will not disable the warning, which is by design
What? they
really want you to force you to write "!= 0" so that the assigned result is inherently of type bool?