tags:

views:

92

answers:

3

Hi all,

I have a class with a static variable: null.

static Pointer<Value> Null;

Pointer is a class which uses reference count memory management.

However, I get an error: no matching function for call to Pointer::Pointer()

On the line:

Pointer<Value> Value::Null(new Value());

Thanks.

Excerpt of Pointer class:

template <typename T>
class Pointer
{
 public:
  explicit Pointer(T* inPtr);

Constructor Source

  mPtr = inPtr;
  if (sRefCountMap.find(mPtr) == sRefCountMap.end()) {  
    sRefCountMap[mPtr] = 1;
  } else {
    sRefCountMap[mPtr]++;
  }
+1  A: 

The line:

static Pointer<Value> Null;

Is call the Pointer::Pointer() constructor. It apears that your Pointer class does not have such a constructor, but instead has a constructor that accepts void*. So try changing it to

static Pointer<Value> Null(0);
Gianni
I still get the error that way.
Maz
Looking at the code you now posted, the problem is that you declared your constructor as `explicit`. That means that either you have to remove the `explicit` keyword or use `reinterpret_cast<0>` or create a new explicit protected constructor for `void*` for that case.
Gianni
A: 

I'm assuming your class is named Value.

// Header file
class Value
{
public:
    ...
    static const Pointer<Value> Null;
};

// This should be in the cpp file.
const Pointer<Value> Value::Null(new Value);
I still get the same error if I try that
Maz
Is the assumption incorrect? Can you show your Value class with the actual Null static member?
Also make sure the class definition for your Pointer template is included in the cpp file and that Value itself is included.
A: 

I believe it should be like:

// In the header file.
class Value
{
public:
    ...
    static const Pointer<Value> Null;
};

// In the cpp file.
const Pointer<Value> Value::Null(reinterpret_cast<Value*>(0));
Vite Falcon
I still get the error that way.
Maz