I am looking at some open source code and I am a bit confused. There is an Allocator class:

class Allocator{

Then in another class, they have:

class Octree{
public:
	static Allocator<OctNode> Allocator;

When trying to compile, I am getting:

error: declaration of 'Allocator<OctNode<NodeData, Real> > OctNode<NodeData, Real>::Allocator'
error: changes meaning of 'Allocator' from 'class Allocator<OctNode<NodeData, Real> >'

which makes sense, because it is like they are trying to make a variable named Allocator of type Allocator, which doesn't make sense. However, this is a pretty well known project so surely it compiles for most people - I am wondering if anyone can tell me if I am interpreting this correctly and why it may compile for others and what I can do to fix it?

Thanks,

Dave

error: changes meaning of 'Allocator' from 'class Allocator<OctNode<NodeData, Real> >'

what is the OctNode class. If it's a template class u have to write it as so

class Octree{
public:
	static Allocator<OctNode<NodeData, Real>> Allocator;

Yes the problem is name reuse. The code compiles fine if you cahgne the name OR you put allocator in a namespace e.g

namespace X
{
template<class T>
class Allocator{
  
public:
  Allocator(void){}
  
};

}

template<class NodeData,class Real=float>
class OctNode
{
private:

public:
  static  X::Allocator<OctNode<NodeData,Real> > Allocator;
};
This article has been dead for over six months. Start a new discussion instead.