Jump to content

View more

Image of the Day

WIP title screen for #DeathOfAPartisan #screenshotsaturday #gamedev https://t.co/qJNhfZCvd4
IOTD | Top Screenshots

The latest, straight to your Inbox.

Subscribe to GameDev.net Direct to receive the latest updates and exclusive content.


Sign up now
- - - - -

Can't create a template class with a default constructor.

4: Adsense

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.


  • You cannot reply to this topic
4 replies to this topic

#1 zeta945@gmail.com   Members   

106
Like
0Likes
Like

Posted 27 October 2012 - 08:41 AM

I'm created a template class,
[source lang="cpp"] r = engine->RegisterObjectType("myObj", 0, asOBJ_REF | asOBJ_NOCOUNT); X_ASSERT0(r >= 0); r = engine->RegisterObjectType("x<class T>", 0, asOBJ_REF | asOBJ_TEMPLATE); assert( r >= 0 ); r = engine->RegisterObjectBehaviour("x<T>", asBEHAVE_FACTORY, "x<T>@ f(int&in)", asFUNCTIONPR(xFactory, (asIObjectType*), x*), asCALL_CDECL); assert( r >= 0 ); r = engine->RegisterObjectBehaviour("x<T>", asBEHAVE_ADDREF, "void f()", asMETHOD(x, addRef), asCALL_THISCALL); assert( r >= 0 ); r = engine->RegisterObjectBehaviour("x<T>", asBEHAVE_RELEASE, "void f()", asMETHOD(x, release), asCALL_THISCALL); assert( r >= 0 );[/source]
then compile my test as code.:
[source lang="cpp"]void test(){ x<myObj> xxx;}[/source]
running it will got an error:

ERR : No default constructor for object of type 'x'.

currently, my solution is use template specializations, register a factory for all my object types.

#2 Andreas Jonsson   Moderators   

4629
Like
0Likes
Like

Posted 28 October 2012 - 09:28 AM

Hi, thanks for the report.

I haven't been able to reproduce this problem with the latest WIP version, though. Which version of AngelScript are you using?

This is the test that I wrote:

asIScriptEngine *engine = asCreateScriptEngine(ANGELSCRIPT_VERSION);
  engine->SetMessageCallback(asMETHOD(CBufferedOutStream, Callback), &bout, asCALL_THISCALL);
 
  r = engine->RegisterObjectType("myObj", 0, asOBJ_REF | asOBJ_NOCOUNT); assert(r >= 0);
  r = engine->RegisterObjectType("x<class T>", 0, asOBJ_REF | asOBJ_TEMPLATE); assert( r >= 0 );
  r = engine->RegisterObjectBehaviour("x<T>", asBEHAVE_FACTORY, "x<T>@ f(int&in)", asFUNCTION(0), asCALL_CDECL); assert( r >= 0 );
  r = engine->RegisterObjectBehaviour("x<T>", asBEHAVE_ADDREF, "void f()", asFUNCTION(0), asCALL_THISCALL); assert( r >= 0 );
  r = engine->RegisterObjectBehaviour("x<T>", asBEHAVE_RELEASE, "void f()", asFUNCTION(0), asCALL_THISCALL); assert( r >= 0 );
  asIScriptModule *mod = engine->GetModule("test", asGM_ALWAYS_CREATE);
  mod->AddScriptSection("test",
   "void test() \n"
   "{ \n"
   "	 x<myObj> xxx; \n"
   "} \n");
  bout.buffer = "";
  r = mod->Build();
  if( r < 0 )
   TEST_FAILED;
  if( bout.buffer != "" )
  {
   printf("%s", bout.buffer.c_str());
   TEST_FAILED;
  }
  engine->Release();

Regards,
Andreas
AngelCode.com - game development and more - Reference DB - game developer references
AngelScript - free scripting library - BMFont - free bitmap font generator - Tower - free puzzle game

#3 zeta945@gmail.com   Members   

106
Like
0Likes
Like

Posted 28 October 2012 - 09:09 PM

Seems my test code has lost one factory registration,

[source lang="cpp"]r = engine->RegisterObjectType("myObj", 0, asOBJ_REF | asOBJ_NOCOUNT); assert(r >= 0);r = engine->RegisterObjectType("x<class T>", 0, asOBJ_REF | asOBJ_TEMPLATE); assert( r >= 0 );r = engine->RegisterObjectBehaviour("x<T>", asBEHAVE_FACTORY, "x<T>@ f(int&in, int)", asFUNCTION(xFactory2), asCALL_CDECL); assert( r >= 0 );r = engine->RegisterObjectBehaviour("x<T>", asBEHAVE_FACTORY, "x<T>@ f(int&in)", asFUNCTION(xFactory), asCALL_CDECL); assert( r >= 0 );r = engine->RegisterObjectBehaviour("x<T>", asBEHAVE_ADDREF, "void f()", asMETHOD(x, addRef), asCALL_THISCALL); assert( r >= 0 );r = engine->RegisterObjectBehaviour("x<T>", asBEHAVE_RELEASE, "void f()", asMETHOD(x, release), asCALL_THISCALL); assert( r >= 0 );[/source]
I'm using version 2.24.1, and I found that when I register default constructor first, the problem solved.
I tested it on the latest WIP version, the same problem.

#4 Andreas Jonsson   Moderators   

4629
Like
0Likes
Like

Posted 29 October 2012 - 06:50 AM

No problem. I'll try again with the new information.
AngelCode.com - game development and more - Reference DB - game developer references
AngelScript - free scripting library - BMFont - free bitmap font generator - Tower - free puzzle game

#5 Andreas Jonsson   Moderators   

4629
Like
0Likes
Like

Posted 29 October 2012 - 05:29 PM

I've fixed the problem in revision 1451.

Thanks,
Andreas
AngelCode.com - game development and more - Reference DB - game developer references
AngelScript - free scripting library - BMFont - free bitmap font generator - Tower - free puzzle game




Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.