Thread: Passing a set to a template function

  1. #1
    Registered User
    Join Date
    Oct 2004
    Posts
    100

    Passing a set to a template function

    Hi all,

    I'm writing this template class and one of the template functions you pass a std::set to of a template type which then returns one of the elements in the set (which is of course a template type). I have wrote it and it compiles fine, however when i cant seem to use the function correctly without the compiler giving an error. Here is what im trying to do.

    This is the template stuff
    Code:
    template<typename myType>
    class MyTemplateClass
    {
     public:
    
    const myType& PickElement (cont std::set<myType>& mySet) const
    {
     // returns one of the elements in the set
    }
    
    };
    Now how do i use the above function? This is what i have currently got:

    Code:
    std::set<MyEnum> enumSet ;
    MyEnum res ;
    
    res = PickElement<MyEnum>(enumSet) ;
    EDIT:
    Doing a full rebuild resulted in a different error:

    The compiler generates the following error:

    Code:
    error C2440: 'type cast' : cannot convert from 'overloaded-function' to 'MyEnum'
    Thanks for any help
    Last edited by cloudy; 10-09-2007 at 02:21 AM.

  2. #2
    Guest Sebastiani's Avatar
    Join Date
    Aug 2001
    Location
    Waterloo, Texas
    Posts
    5,708
    PickElement is not a templated function. simply call it like:

    Code:
    res = PickElement(enumSet) ;
    Code:
    #include <cmath>
    #include <complex>
    bool euler_flip(bool value)
    {
        return std::pow
        (
            std::complex<float>(std::exp(1.0)), 
            std::complex<float>(0, 1) 
            * std::complex<float>(std::atan(1.0)
            *(1 << (value + 2)))
        ).real() < 0;
    }

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Getting an error with OpenGL: collect2: ld returned 1 exit status
    By Lorgon Jortle in forum C++ Programming
    Replies: 6
    Last Post: 05-08-2009, 08:18 PM
  2. template function v.s. template class
    By George2 in forum C++ Programming
    Replies: 3
    Last Post: 12-13-2007, 01:46 AM
  3. Replies: 28
    Last Post: 07-16-2006, 11:35 PM
  4. error: template with C linkage
    By michaels-r in forum C++ Programming
    Replies: 3
    Last Post: 05-17-2006, 08:11 AM
  5. Replies: 5
    Last Post: 02-08-2003, 07:42 PM