| | |
Redefined name?
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Feb 2008
Posts: 628
Reputation:
Solved Threads: 46
I am looking at some open source code and I am a bit confused. There is an Allocator class:
Then in another class, they have:
When trying to compile, I am getting:
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
C++ Syntax (Toggle Plain Text)
class Allocator{
Then in another class, they have:
C++ Syntax (Toggle Plain Text)
class Octree{ public: static Allocator<OctNode> Allocator;
When trying to compile, I am getting:
C++ Syntax (Toggle Plain Text)
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
0
#3 Oct 12th, 2009
C++ Syntax (Toggle Plain Text)
error: changes meaning of 'Allocator' from 'class Allocator<OctNode<NodeData, Real> >'
C++ Syntax (Toggle Plain Text)
class Octree{ public: static Allocator<OctNode<NodeData, Real>> Allocator;
•
•
Join Date: Feb 2008
Posts: 628
Reputation:
Solved Threads: 46
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?
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?
•
•
Join Date: Nov 2008
Posts: 392
Reputation:
Solved Threads: 72
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
c++ Syntax (Toggle Plain Text)
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; };
experience is the most expensive way to learn anything
![]() |
Similar Threads
- RedHat 8 (*nix Software)
- Which of these current affairs most worries you? (IT Professionals' Lounge)
- radio button ASP question?? (ASP)
- class array problem! (C++)
- Need example of how to use INHERITANCE! (C++)
- Randomize number with OpenGL (C++)
Other Threads in the C++ Forum
- Previous Thread: pointers problem
- Next Thread: hello
| Thread Tools | Search this Thread |
api array beginner binary bitmap c++ c/c++ calculator char char* class classes coding compile compiler console conversion count database delete desktop developer directshow dll download dynamic dynamiccharacterarray email encryption error file forms fstream function functions game google graph gui homeworkhelper iamthwee ifstream input int integer java lib linkedlist linker linux list loop looping loops map math matrix memory multiple news node number numbertoword output parameter pointer problem program programming project proxy python random read recursion recursive reference return rpg sorting string strings struct template templates test text text-file tree unix url vector video visualstudio win32 windows winsock word wordfrequency wxwidgets





