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 6850703
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T01:09:28+00:00 2026-05-27T01:09:28+00:00

I used to have a normal member variable, which was initialized in the constructors

  • 0

I used to have a normal member variable, which was initialized in the constructors as following:

ResourceSaveFunctions[OBJECTS_IDENT] = NULL;
ResourceSaveFunctions[SPRITES_IDENT] = &GMProject::SaveSprite;
ResourceSaveFunctions[SOUNDS_IDENT] = &GMProject::SaveSound;
ResourceSaveFunctions[BACKGROUNDS_IDENT] = &GMProject::SaveBackground;
ResourceSaveFunctions[PATHS_IDENT] = NULL;
ResourceSaveFunctions[SCRIPTS_IDENT] = NULL;
ResourceSaveFunctions[FONTS_IDENT] = NULL;
ResourceSaveFunctions[TIMELINES_IDENT] = NULL;
ResourceSaveFunctions[ROOMS_IDENT] = NULL;
ResourceSaveFunctions["extension"] = &GMProject::SaveExtension;
ResourceSaveFunctions[INCLUDES_IDENT] = NULL;
ResourceSaveFunctions[TRIGGERS_IDENT] = NULL;

The variable is a map with as key strings, and as data member-function-pointers. This worked perfectly fine. However as said I believe this map should be static (?) – the reason for the map is just to identify what the program should do during reading of a file. – NULL meaning “do nothing special”.

So I changed it to the following:

std::map<std::string, GMProject::GMProjectMemFn> GMProject::ResourceSaveFunctions_INIT() {
    std::map<std::string, GMProjectMemFn> tmp;
    tmp.insert(std::make_pair(OBJECTS_IDENT,NULL));
    tmp.insert(std::make_pair(SPRITES_IDENT, &GMProject::SaveSprite));
    tmp.insert(std::make_pair(SOUNDS_IDENT, &GMProject::SaveSound));
    tmp.insert(std::make_pair(BACKGROUNDS_IDENT, &GMProject::SaveBackground));
    tmp.insert(std::make_pair(PATHS_IDENT, NULL));
    tmp.insert(std::make_pair(SCRIPTS_IDENT, NULL));
    tmp.insert(std::make_pair(FONTS_IDENT, NULL));
    tmp.insert(std::make_pair(TIMELINES_IDENT, NULL));
    tmp.insert(std::make_pair(ROOMS_IDENT, NULL));
    tmp.insert(std::make_pair("extension", &GMProject::SaveExtension));
    tmp.insert(std::make_pair(INCLUDES_IDENT, NULL));
    tmp.insert(std::make_pair(TRIGGERS_IDENT, NULL));
    return tmp;
}
const std::map<std::string, GMProject::GMProjectMemFn> GMProject::ResourceSaveFunctions(GMProject::ResourceSaveFunctions_INIT());

Where those things are declared in the header:

static const std::map<std::string, GMProjectMemFn> ResourceSaveFunctions;
static std::map<std::string, GMProjectMemFn> ResourceSaveFunctions_INIT();

Now compiling suddenly brings up a lot of errors.

1>c:\program files\microsoft visual studio 10.0\vc\include\utility(163): error C2440: ‘initializing’ : cannot convert from ‘int’ to ‘GMProject::GMProjectMemFn ‘

Which is about the conversion of NULL. However shouldn’t this be just possible? Why is this not possible (yet in the previous method it was)?
Should I use an explicit cast here?

EDIT:
GMProjectMemFn defined as following:

typedef void (GMProject::*GMProjectMemFn)(const pTree&) const; 

pTree being a container.

  • 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-05-27T01:09:28+00:00Added an answer on May 27, 2026 at 1:09 am

    std::make_pair creates a pair<T1, T2> where the types T1 and T2 are deduced implicitly from the types of the arguments. NULL expands to 0 (or 0L) so in your case make_pair returns a pair<string, int> (or a pair<string, long>).

    You then try passing that pair<string, int> to map<string, GMProject::GMProjectMemFn>::insert() but this expects a pair<string, GMProjectMemFn>.

    std::pair has a general copy constructor which will attempt implicit conversion of each member of the pair:

    template <class U, class V>
        pair (const pair<U,V> &p) : first(p.first), second(p.second) { }
    

    but in your case this requires converting a const int& to a pointer, which is not permitted.

    In your original case you were directly converting NULL into a pointer, which is well defined.

    Explicitly typing your pair should fix this:

    tmp.insert(std::pair<std::string, GMProject::GMProjectMemFn>(TIMELINES_IDENT, NULL));
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have used this in my HTML: <q> Hai How r u </q> Which
During my apprenticeship, I have used NHibernate for some smaller projects which I mostly
The following code shows a normal event and a routed event. Here I have
Using Symfony 1.3 I have a normal form-filter that is used to filter values
I have a normal project and use ClickOnce. Today, following a new implementation, ClickOnce
I'm using sorted sets in the following way. I have a normal set called
I have a normal Drupal User. I have used the content_profile module to create
I have used traditional version control systems to maintain source code repositories on past
I have used IPC in Win32 code a while ago - critical sections, events,
I have used the XML Parser before, and even though it worked OK, I

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.