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

Any ideas?

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;

Hm I tried that - didn't seem to work. Here is a super simplified version that produces the same error:

http://www.rpi.edu/~doriad/Daniweb/octree/

I still think the problem is simply that they tried to re-use a name? Is this the case?

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;
};
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.