Redefined name?

Please support our C++ advertiser: Intel Parallel Studio Home
Reply

Join Date: Feb 2008
Posts: 628
Reputation: daviddoria is a jewel in the rough daviddoria is a jewel in the rough daviddoria is a jewel in the rough 
Solved Threads: 46
daviddoria daviddoria is offline Offline
Practically a Master Poster

Redefined name?

 
0
  #1
Oct 9th, 2009
I am looking at some open source code and I am a bit confused. There is an Allocator class:
  1. class Allocator{

Then in another class, they have:
  1. class Octree{
  2. public:
  3. static Allocator<OctNode> Allocator;

When trying to compile, I am getting:
  1. error: declaration of 'Allocator<OctNode<NodeData, Real> > OctNode<NodeData, Real>::Allocator'
  2. 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
Reply With Quote Quick reply to this message  
Join Date: Feb 2008
Posts: 628
Reputation: daviddoria is a jewel in the rough daviddoria is a jewel in the rough daviddoria is a jewel in the rough 
Solved Threads: 46
daviddoria daviddoria is offline Offline
Practically a Master Poster
 
0
  #2
Oct 12th, 2009
Any ideas?
Reply With Quote Quick reply to this message  
Join Date: Sep 2009
Posts: 335
Reputation: dkalita will become famous soon enough dkalita will become famous soon enough 
Solved Threads: 48
dkalita's Avatar
dkalita dkalita is offline Offline
Posting Whiz
 
0
  #3
Oct 12th, 2009
  1. 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
  1. class Octree{
  2. public:
  3. static Allocator<OctNode<NodeData, Real>> Allocator;
Reply With Quote Quick reply to this message  
Join Date: Feb 2008
Posts: 628
Reputation: daviddoria is a jewel in the rough daviddoria is a jewel in the rough daviddoria is a jewel in the rough 
Solved Threads: 46
daviddoria daviddoria is offline Offline
Practically a Master Poster
 
0
  #4
Oct 12th, 2009
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?
Reply With Quote Quick reply to this message  
Join Date: Nov 2008
Posts: 392
Reputation: StuXYZ is a glorious beacon of light StuXYZ is a glorious beacon of light StuXYZ is a glorious beacon of light StuXYZ is a glorious beacon of light StuXYZ is a glorious beacon of light StuXYZ is a glorious beacon of light 
Solved Threads: 72
StuXYZ StuXYZ is offline Offline
Posting Whiz
 
0
  #5
Oct 12th, 2009
Yes the problem is name reuse. The code compiles fine if you cahgne the name OR you put allocator in a namespace e.g
  1. namespace X
  2. {
  3. template<class T>
  4. class Allocator{
  5.  
  6. public:
  7. Allocator(void){}
  8.  
  9. };
  10.  
  11. }
  12.  
  13. template<class NodeData,class Real=float>
  14. class OctNode
  15. {
  16. private:
  17.  
  18. public:
  19. static X::Allocator<OctNode<NodeData,Real> > Allocator;
  20. };
experience is the most expensive way to learn anything
Reply With Quote Quick reply to this message  
Reply

Message:



Similar Threads
Other Threads in the C++ Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC