what's wrong with this map definition?

This is a discussion on what's wrong with this map definition? within the C++ Programming forums, part of the General Programming Boards category; The error is : loganalyzer.cpp: In member function ‘void Loganalyzer::conditionaldistribution(size_t, size_t, size_t, size_t, size_t, double)’: loganalyzer.cpp:1091: error: template argument for ...

  1. #1
    Registered User
    Join Date
    Dec 2008
    Posts
    48

    what's wrong with this map definition?

    The error is :
    loganalyzer.cpp: In member function ‘void Loganalyzer::conditionaldistribution(size_t, size_t, size_t, size_t, size_t, double)’:
    loganalyzer.cpp:1091: error: template argument for ‘template<class _T1, class _T2> struct std:air’ uses local type ‘Loganalyzer::conditionaldistribution(size_t, size_t, size_t, size_t, size_t, double)::Count’
    loganalyzer.cpp:1091: error: trying to instantiate ‘template<class _T1, class _T2> struct std:air’
    loganalyzer.cpp:1091: error: template argument 4 is invalid
    loganalyzer.cpp:1091: error: invalid type in declaration before ‘;’ token


    Code:
    void Loganalyzer::conditionaldistribution(size_t T, size_t S, size_t N, size_t f, size_t SIZE, double alpha) {
    
    	typedef int pathcode;
    
    	typedef struct {
    	public:
    		int countall;
    		int countplus;
    		int countminus;
    	} Count;
    
    	map<pathcode, Count > count;
    ...
    }

  2. #2
    and the hat of sweating
    Join Date
    Aug 2007
    Location
    Toronto, ON
    Posts
    3,545
    Can you post line 1091?
    "I am probably the laziest programmer on the planet, a fact with which anyone who has ever seen my code will agree." - esbo, 11/15/2008

    "the internet is a scary place to be thats why i dont use it much." - billet, 03/17/2010

  3. #3
    Captain Crash brewbuck's Avatar
    Join Date
    Mar 2007
    Location
    Portland, OR
    Posts
    7,230
    You can't use a function-locally defined type as a template parameter. The message means exactly what it says. Lift the struct definition out to the global scope.
    Code:
    //try
    //{
    	if (a) do { f( b); } while(1);
    	else   do { f(!b); } while(1);
    //}

  4. #4
    and the hat of sweating
    Join Date
    Aug 2007
    Location
    Toronto, ON
    Posts
    3,545
    Interesting... Is there a reason why a function local struct can't be a map member?
    "I am probably the laziest programmer on the planet, a fact with which anyone who has ever seen my code will agree." - esbo, 11/15/2008

    "the internet is a scary place to be thats why i dont use it much." - billet, 03/17/2010

  5. #5
    Registered User
    Join Date
    Jun 2005
    Posts
    6,163
    Quote Originally Posted by cpjust View Post
    Interesting... Is there a reason why a function local struct can't be a map member?
    Template instances are required to have external linkage, otherwise it would not be possible to instantiate templates without violating the one-definition rule. A side effect of that requirement is that the types used to instantiate a template must also have external linkage. Types that are local to a function do not have external linkage, by definition.
    Right 98% of the time, and don't care about the other 3%.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Multiple Definition Error
    By timmeh in forum C++ Programming
    Replies: 9
    Last Post: 02-15-2009, 11:25 AM
  2. Creating a map of objects with variable width and height
    By MrSparky in forum C++ Programming
    Replies: 6
    Last Post: 07-30-2007, 03:06 PM
  3. game map format preference
    By valis in forum Tech Board
    Replies: 2
    Last Post: 07-02-2006, 02:16 PM
  4. God
    By datainjector in forum A Brief History of Cprogramming.com
    Replies: 746
    Last Post: 12-22-2002, 11:01 AM
  5. my map is showing up 90 degrees turned!
    By frenchfry164 in forum C++ Programming
    Replies: 8
    Last Post: 03-28-2002, 01:32 PM

Tags for this Thread


1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21