| | |
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 ansi api array asterisks binarysearch calculate centimeter char character cm convert copyanyfile copyimagefile copypdffile cprogramme createcopyoffile createprocess() csyntax directory feet fflush fgets file floatingpointvalidation fork frequency function getlasterror getlogicaldrivestrin givemetehcodez global graphics gtkgcurlcompiling gtkwinlinux hacking highest homework i/o inches infiniteloop interest intmain() kilometer km linked linkedlist linux linuxsegmentationfault list locate logical_drives match meter microsoft mqqueue mysql number oddnumber odf open opendocumentformat openwebfoundation owf pattern pdf performance posix power probleminc program programming pyramidusingturboccodes read recv recvblocked repetition scanf scheduling segmentationfault send single socketprograming socketprogramming stack standard strchr string suggestions systemcall unix urboc user variable voidmain() wab whythiscodecausesegmentationfault win32api windows.h






