Advertisement
Advertisement
| 04.25.2008 at 08:06PM PDT, ID: 23355400 |
|
[x]
Attachment Details
|
||
|
[x]
The Solution Rating System
|
||
|
With so many solutions, how can you tell which solutions are most likely to help you and which ones are not? To provide you with a tool to use, we rate our solutions based on various elements that most accurately determine if a solution is a quality solution. To explain what factors affect the solution rating, here are the elements we take into consideration when formulating our solution rating.
Your Input Matters If you have any suggestions that you would like to make for our rating system, please ask a question in the Suggestions Zone of Community Support. Thank you! |
||
| Microsoft |
| Apple |
| Internet |
| Gamers |
| Digital Living |
| Virus & Spyware |
| Hardware |
| Software |
| ITPro |
| Developer |
| Storage |
| OS |
| Database |
| Security |
| Programming |
| Web Development |
| Networking |
| Other |
| Community Support |
| 04.25.2008 at 09:08PM PDT, ID: 21444454 |
| 04.25.2008 at 09:40PM PDT, ID: 21444534 |
| 04.25.2008 at 10:57PM PDT, ID: 21444678 |
| 04.26.2008 at 01:22AM PDT, ID: 21444891 |
| 04.26.2008 at 06:06AM PDT, ID: 21445406 |
| 04.26.2008 at 06:26AM PDT, ID: 21445449 |
| 04.26.2008 at 12:11PM PDT, ID: 21446556 |
| 04.26.2008 at 09:37PM PDT, ID: 21448155 |
| 04.26.2008 at 09:39PM PDT, ID: 21448162 |
| 04.26.2008 at 09:48PM PDT, ID: 21448183 |
| 04.26.2008 at 11:22PM PDT, ID: 21448335 |
| 04.27.2008 at 01:46AM PDT, ID: 21448537 |
| 04.27.2008 at 09:50AM PDT, ID: 21449631 |
1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37: 38: 39: 40: 41: 42: 43: 44: 45: 46: 47: 48: 49: 50: 51: 52: 53: 54: 55: 56: 57: 58: 59: 60: 61: 62: 63: 64: 65: 66: 67: 68: 69: 70: 71: 72: 73: 74: 75: 76: 77: 78: 79: 80: 81: 82: 83: 84: 85: 86: 87: 88: 89: 90: 91: 92: 93: 94: 95: 96: |
#include "stdafx.h"
#include "stdlib.h"
#include <assert.h>
#include <new>
class A
{
virtual long Increase() = 0;
virtual long Decrease() = 0;
};
class B : public A
{
virtual void Set(long n) = 0;
virtual long Get() = 0;
};
class C : public A
{
public:
C() : m_count(1)
{
}
virtual ~C()
{
}
long Increase(){return ++m_count;}
long Decrease()
{
long n = --m_count;
if (n == 0) {
// RX: This is dangerous, say this is a stack based object?
// You should protect agains thtis by making constructor private
// and using a static factory function
delete this;
}
return n;
}
protected:
long m_count;
};
class D : public B
{
public:
D() : m_count(0), m_n(99)
{
}
virtual ~D()
{
}
long Increase(){return ++m_count;}
long Decrease()
{
long n = --m_count;
if (n == 0) {
this->~D();
// RX: It is not safe to mix realloc and new. The original object was allocated using new
// There is no reason to believe that realloc will work with the same heap as new.
// Also, say this is a stack based object? You should protect agains thtis by making
// constructor private and using a static factory function. I'm also not sure that
// manipulating the this pointer in this way is a good idea. What if you then try to use
// this again in the context of D? Also, realloc might return a pointer to a diffent area
// of memory or even NULL! I think this will try to free the original memory (bang!) and
// assign new memory to p, which is a local so when it goes out of scope you'll leak memory
void* p = realloc(reinterpret_cast<void*>(this), sizeof(C));
new(p) C;
}
return n;
}
void Set(long n)
{
m_n = n;
}
long Get()
{
return m_n;
}
protected:
long m_count;
long m_n;
};
int main(int argc, char* argv[])
{
D* pD = new D;
long n = pD->Increase();
n = pD->Get();
pD->Set(7);
n = pD->Get();
n = pD->Decrease();
n = pD->Decrease();
return 0;
}
|