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

  • SEARCH
  • Home
  • 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 8798311
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T00:04:02+00:00 2026-06-14T00:04:02+00:00

I am passing a method into a constructor, but when I used a method

  • 0

I am passing a method into a constructor, but when I used a method that another class, it gives me an error.

It is currently working in this form;

unsigned int pHash(const std::string& str)
{
    //method
}
int main()
{
//stuff
HashMap* hm2 = new HashMap(pHash);
//stuff
}

However, if I reference another header file’s method like so;

HashMap* hm2 = new HashMap(&HashFcn::primeHash);

I get an error at runtime with the follow messages;

Error   1   error C2100: illegal indirection    c:\program files (x86)\microsoft visual studio 11.0\vc\include\xrefwrap 273 1   Project
    Error   2   error C2440: 'newline' : cannot convert from 'const std::string *' to 'const HashFcn *' c:\program files (x86)\microsoft visual studio 11.0\vc\include\xrefwrap 273 1   Project
    Error   3   error C2647: '.*' : cannot dereference a 'unsigned int (__thiscall HashFcn::* )(const std::string &)' on a 'const std::string'  c:\program files (x86)\microsoft visual studio 11.0\vc\include\xrefwrap 273 1   Project

My hashmap constructor looks like this;

HashMap::HashMap(HashFunction hashFunction)
    : hfunc(hashFunction)

where hfunc is a typdef of a method.

I have a class HashFcn which has the method primeHash

unsigned int primeHash(const std::string&);

This is my first time doing typdef / method passing — any clues or help would be greatly appreciated!

  • 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-14T00:04:03+00:00Added an answer on June 14, 2026 at 12:04 am

    try making primeHash static:

      static unsigned int primeHash(const std::string&);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have some class that I'm passing as a result of a service method,
What is the correct way of passing the drawing context to another method in
Objective-C uses a sophisticated message-passing system when one object calls a method on another
The Law of Demeter does not prevent passing objects into class constructors. However, it
I'm using the initializer list method for my class constructor. I initialize my variables
In my service facade layer, I have a service class with a method/operation that
I'm currently implementing a copy constructor for a Linked List class. When I create
Hi I have a class which includes an array, I'm not passing this through
Of course enum's don't exist in Ruby, but based on this post I've used
I have a get method passing in an object of type Store to the

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.