| | |
templates and maps
![]() |
•
•
Join Date: Jun 2004
Posts: 2,108
Reputation:
Solved Threads: 18
I've got the following code:
The following line always gives me an error saying ';' expected before find_occur.
map<T,int>::iterator find_occur = frequency.find(obj);
If I change the first argument of the map to something other than T, then it works fine, but I need the template type. Is there something I'm doing wrong?
C Syntax (Toggle Plain Text)
template <typename T> int Histogram<T>::get_occurances(const T& obj) { map<T,int>::iterator find_occur = frequency.find(obj); if ( find_occur == this->frequency.end() ) { return 0; } return ( find_occur->second ); }
The following line always gives me an error saying ';' expected before find_occur.
map<T,int>::iterator find_occur = frequency.find(obj);
If I change the first argument of the map to something other than T, then it works fine, but I need the template type. Is there something I'm doing wrong?
•
•
Join Date: Apr 2006
Posts: 8
Reputation:
Solved Threads: 1
A type that depends on a template parameter needs to be qualified with the typename keyword.
template <typename T> int Histogram<T>::get_occurances(const T& obj)
{
typename map<T,int>::iterator find_occur = frequency.find(obj);
if ( find_occur == this->frequency.end() )
{
return 0;
}
return ( find_occur->second );
}![]() |
Similar Threads
- Great Place for free templates and other resources. (Site Layout and Usability)
- How to create image maps that look so nice... (Graphics and Multimedia)
- More psd templates (Website Reviews)
- RTC Templates - Talented designers required (Software Development Job Offers)
- Templates (Websites for Sale)
- C++ Templates (C++)
Other Threads in the C Forum
- Previous Thread: help with pointers in this fucntion
- Next Thread: Help! Unknown bug in Writing to file
| Thread Tools | Search this Thread |
adobe api array arrays binarysearch calculate char cm convert copyanyfile copypdffile cprogramme createcopyoffile createprocess() csyntax directory dynamic feet fflush file floatingpointvalidation fork forloop frequency getlasterror givemetehcodez global graphics gtkgcurlcompiling hacking hardware highest homework i/o inches incrementoperators intmain() iso kernel kilometer km linked linkedlist linux linuxsegmentationfault list locate logical_drives loopinsideloop. match matrix microsoft motherboard mqqueue mysql oddnumber odf open opendocumentformat opensource openwebfoundation owf pattern pdf performance pointer posix power probleminc program programming pyramidusingturboccodes read recursion recv recvblocked repetition research scanf scheduling segmentationfault send shape socketprograming socketprogramming stack standard strchr string suggestions systemcall test unix urboc user variable voidmain() wab win32api windows.h






