CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5
  1. #1
    Join Date
    Dec 2010
    Posts
    907

    error C3203: 'set' : unspecialized class template can't be used as a template

    I have tried both const QuadNode* and const QuadNode& to no avail.
    Thanks
    Jack

    Code:
    std::map<std::string, std::set<QuadNode*, QuadNodeSortedComparator>> activePool;
    
    struct QuadNodeSortedComparator 
    {
    	bool operator()(const QuadNode& node1, const QuadNode& node2) const {	  
    		return std::tie(node1.x, node1.z) < std::tie(node2.x, node2.z);
    
    	}
    
    };

  2. #2
    Join Date
    Jun 2015
    Posts
    208

    Re: error C3203: 'set' : unspecialized class template can't be used as a template

    Since the set is holding pointers I think you should access the members by ->, like node1->x rather than node1.x.
    Last edited by tiliavirga; September 16th, 2015 at 02:05 AM.

  3. #3
    Join Date
    Jun 2009
    Location
    France
    Posts
    2,513

    Re: error C3203: 'set' : unspecialized class template can't be used as a template

    Quote Originally Posted by lucky6969b View Post
    I have tried both const QuadNode* and const QuadNode& to no avail.
    Thanks
    Jack

    Code:
    std::map<std::string, std::set<QuadNode*, QuadNodeSortedComparator>> activePool;
    
    struct QuadNodeSortedComparator 
    {
    	bool operator()(const QuadNode& node1, const QuadNode& node2) const {	  
    		return std::tie(node1.x, node1.z) < std::tie(node2.x, node2.z);
    
    	}
    
    };
    Please provide the actual code that you used to produce the error. You just provided a snipet, and all it would produce is "error: 'QuadNodeSortedComparator' was not declared in this scope".

    Appart from the fact that you are using a function that takes "const QuadNode&" to compare "QuadNode*" objects, I see nothing wrong with the code, provided you use the correct forward declarations etc.

    But the devil is in the details:
    - What is your "QuadNode" definition?
    - What are your includes?
    - What and where are your forward declarations?

    Please provide a short but *complete* example that reproduces your issue.
    Is your question related to IO?
    Read this C++ FAQ article at parashift by Marshall Cline. In particular points 1-6.
    It will explain how to correctly deal with IO, how to validate input, and why you shouldn't count on "while(!in.eof())". And it always makes for excellent reading.

  4. #4
    Join Date
    Dec 2010
    Posts
    907

    Re: error C3203: 'set' : unspecialized class template can't be used as a template

    Hello, I change it back to QuadNode instead of QuadNode*, everything works great now.
    Thanks for helping
    Jack

  5. #5
    Join Date
    Jun 2015
    Posts
    208

    Re: error C3203: 'set' : unspecialized class template can't be used as a template

    Quote Originally Posted by lucky6969b View Post
    I change it back to QuadNode instead of QuadNode*, everything works great now.
    And the reason for that is that the set now holds QuadNode objects rather than QuadNode pointers. In the first case it's okay to access QuadNode members using . whereas in the second case you must use -> instead. Also in the second case it's kind of overkill to pass in the pointers by const reference to the () operator.
    Last edited by tiliavirga; September 16th, 2015 at 04:12 AM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured