Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9190883
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T20:33:41+00:00 2026-06-17T20:33:41+00:00

my problem is I try to call my template function test which takes pointer

  • 0

my problem is I try to call my template function test which takes pointer to another template function. since you can’t have templated pointer to function I did it by wrapping such typedef pointer in struct (see Template typedefs – What's your work around?). it’s OK – I can call my template function by a pointer, but problem is that I can’t call function that takes this pointer as argument. error in VS2010 is:

c:\projects\sort\sort\sort.cpp(114): error C2059: syntax error : ‘}’
c:\projects\sort\sort\sort.cpp(124) : see reference to function template instantiation ‘void test(void (__cdecl *)(std::vector<_Ty> &))’ being compiled
with
[
_Ty=int
]

Build FAILED.

_Ty is int, and it is OK, right?

#include "stdafx.h"
#include <vector>
#include <iterator>//for ostream_iterator
#include <algorithm>//for copy
#include <iostream>//for cout
#include <map>
#include <boost/timer/timer.hpp>
#include <boost/random.hpp>
#include <functional>

template <typename T>
void insert_sort(typename std::vector<T>& v){ // O(n^2)
    for(std::vector<T>::iterator it=v.begin();it!=v.end();it++){
        std::vector<T>::iterator it2=it; // [0,...,i-1] has been sorted already
        T temp = *it2;
        while(it2!=v.begin() && *(it2-1)>temp){
            *(it2)=*(it2-1);
            it2--;
        }
        *(it2)=temp;
    }
}
void f(int i){std::cout<<i<<" ";}

template<typename T>
struct sort_struct{
    typedef void (*func_sort)(std::vector<T>& );
    typedef std::map<int,T> mymap;
};

template<typename T>
double sortTime(std::vector<T>& v, typename sort_struct<T>::func_sort f){
    boost::timer t; // start timing
    f(v);
    return t.elapsed();
}

template<typename T>
void test(typename sort_struct<T>::func_sort f){
    int i=100;
    while(i<0xFF){
        boost::mt19937 marsenneTwister;
        boost::uniform_int<> unigen;
        boost::variate_generator<boost::mt19937, boost::uniform_int<> > 
            gen(marsenneTwister, unigen);
        std::vector<int> randVec(i);
        std::random_shuffle(randVec.begin(), randVec.end(), gen);
        double elapsed = sortTime(randVec,f);
        std::cout<<i<<","<<elapsed<<std::endl;
            i+=100;
    }
}


int _tmain(int argc, _TCHAR* argv[])
{
    std::vector<int> vi(2);
    sort_struct<int>::func_sort isort_int=insert_sort<int>;
    (*isort_int)(vi); // this is OK

    // how to instantiate and call test<int> ?
    test<int>(isort_int); // error
    //...
 }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T20:33:42+00:00Added an answer on June 17, 2026 at 8:33 pm

    This line is the problem:

    while(i<0xFF)do{
    

    The correct syntax is

    while(i<0xFF){
    

    .

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have another problem. Im getting an internal server error when I try to
I have no problem passing the address of a function template specialization to a
I have a member function in my base class which takes argument by reference:
I got a little problem. Sometimes, when I try to call the following code,
i am having this problem try to use the cocos2d CCScrollLayer I have added
i have a problem when try to get and parse a remote JSON. require
I have a problem when try to use hashtable with large data. I have
I'm having a problem with TRY...CATCH blocks. Can someone explain why the following code
I have a problem when I try to count how many times a word
I have a problem when I try to persist my model. An exception is

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.