template instantiation
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5

Thread: template instantiation

Threaded View

  1. #1
    Join Date
    Sep 2010
    Posts
    39

    namespace problems

    Hi, The simplified code compiles correctly under GCC but not MSVC. why ? If I put Option struct in its own named namespace or remove the namespace Util, it compiles correclty. How can I make it work for both compilers ?
    Code:
    #include <vector>
    #include <iostream>
    
    /*default vector IO*/
    template <class T>
    std::ostream& operator << (std::ostream& os, const std::vector<T>& p) {
    	return os;
    }
    template <class T>
    std::istream& operator >> (std::istream& is, std::vector<T>& p) {
    	return is;
    }
    
    /*Utililty functions*/
    namespace Util {
    
    	/*options*/
    	struct Option {
    		friend std::istream& operator >> (std::istream& is, Option& p) {
    			return is;
    		}
    		friend std::ostream& operator << (std::ostream& os, const Option& p) {
    			return os;
    		}
    	};
    
    	/*parameters*/
    	struct Parameters{
    		std::vector<int>* test;
    		bool read(std::string str,std::istream& is) {
    			is >> *test;
    			return false;
    		}
    	};
    	/*end*/
    }
    
    void main() {
    	Util::Parameters params_vec_int;
    	params_vec_int.read("test",std::cin);
    }
    Last edited by dshawul; January 26th, 2013 at 11:18 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
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center