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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T15:38:57+00:00 2026-05-10T15:38:57+00:00

I am hosting SpiderMonkey in a current project and would like to have template

  • 0

I am hosting SpiderMonkey in a current project and would like to have template functions generate some of the simple property get/set methods, eg:

template <typename TClassImpl, int32 TClassImpl::*mem> JSBool JS_DLL_CALLBACK WriteProp(JSContext* cx, JSObject* obj, jsval id, jsval* vp) {     if (TClassImpl* pImpl = (TClassImpl*)::JS_GetInstancePrivate(cx, obj, &TClassImpl::s_JsClass, NULL))         return ::JS_ValueToInt32(cx, *vp, &(pImpl->*mem));     return JS_FALSE; } 

Used:

::JSPropertySpec Vec2::s_JsProps[] = {     {'x', 1, JSPROP_PERMANENT, &JsWrap::ReadProp<Vec2, &Vec2::x>, &JsWrap::WriteProp<Vec2, &Vec2::x>},     {'y', 2, JSPROP_PERMANENT, &JsWrap::ReadProp<Vec2, &Vec2::y>, &JsWrap::WriteProp<Vec2, &Vec2::y>},     {0} }; 

This works fine, however, if I add another member type:

template <typename TClassImpl, JSObject* TClassImpl::*mem> JSBool JS_DLL_CALLBACK WriteProp(JSContext* cx, JSObject* obj, jsval id, jsval* vp) {     if (TClassImpl* pImpl = (TClassImpl*)::JS_GetInstancePrivate(cx, obj, &TClassImpl::s_JsClass, NULL))         return ::JS_ValueToObject(cx, *vp, &(pImpl->*mem));     return JS_FALSE; } 

Then Visual C++ 9 attempts to use the JSObject* wrapper for int32 members!

1>d:\projects\testing\jswnd\src\main.cpp(93) : error C2440: 'specialization' : cannot convert from 'int32 JsGlobal::Vec2::* ' to 'JSObject *JsGlobal::Vec2::* const ' 1>        Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast 1>d:\projects\testing\jswnd\src\main.cpp(93) : error C2973: 'JsWrap::ReadProp' : invalid template argument 'int32 JsGlobal::Vec2::* ' 1>        d:\projects\testing\jswnd\src\wrap_js.h(64) : see declaration of 'JsWrap::ReadProp' 1>d:\projects\testing\jswnd\src\main.cpp(93) : error C2440: 'initializing' : cannot convert from 'overloaded-function' to 'JSPropertyOp' 1>        None of the functions with this name in scope match the target type 

Surprisingly, parening JSObject* incurs a parse error! (unexpected ‘(‘). This is probably a VC++ error (can anyone test that ‘template void foo() {}’ compiles in GCC?). Same error with ‘typedef JSObject* PObject; …, PObject TClassImpl::mem>’, void, struct Undefined*, and double. Since the function usage is fully instantiated: ‘&ReadProp’, there should be no normal function overload semantics coming into play, it is a defined function at that point and gets priority over template functions. It seems the template ordering is failing here.

Vec2 is just:

class Vec2 { public:     int32 x, y;      Vec2(JSContext* cx, JSObject* obj, uintN argc, jsval* argv);      static ::JSClass s_JsClass;     static ::JSPropertySpec s_JsProps[]; }; 

JSPropertySpec is described in JSAPI link in OP, taken from header:

typedef JSBool (* JS_DLL_CALLBACK JSPropertyOp)(JSContext *cx, JSObject *obj, jsval id,                                  jsval *vp);  ...  struct JSPropertySpec {     const char      *name;     int8            tinyid;     uint8           flags;     JSPropertyOp    getter;     JSPropertyOp    setter; }; 
  • 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. 2026-05-10T15:38:58+00:00Added an answer on May 10, 2026 at 3:38 pm

    Pretty sure VC++ has ‘issues’ here. Comeau and g++ 4.2 are both happy with the following program:

    struct X {     int i;     void* p; };  template<int X::*P> void foo(X* t) {     t->*P = 0; }  template<void* X::*P> void foo(X* t) {     t->*P = 0; }  int main() {     X x;     foo<&X::i>(&x);     foo<&X::p>(&x); } 

    VC++ 2008SP1, however, is having none of it.

    I haven’t the time to read through my standard to find out exactly what’s what… but I think VC++ is in the wrong here.

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

Sidebar

Related Questions

No related questions found

Ask A Question

Stats

  • Questions 58k
  • Answers 58k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • added an answer Not that I know of. But you can use the… May 11, 2026 at 8:52 am
  • added an answer OK, after 8 hours of frustration I've got to the… May 11, 2026 at 8:52 am
  • added an answer I have heard of issues like this over vpn connections.… May 11, 2026 at 8:52 am

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.