Jump to content

  • Log In with Google      Sign In   
  • Create Account


Sir Ementaler

Member Since 09 Mar 2013
Offline Last Active Today, 02:44 AM
-----

Topics I've Started

Default constructors vs default arguments

22 August 2013 - 05:45 AM

Let's consider a simple class declared within a script:

class foo{
  foo(){
    //...
  }
}

I can create its instances in both of these two ways:

foo foo1();
foo foo2;

Now let's consider a similar class, but give its constructor a parameter that can have a default value:

class foo{
  foo(int bar=0){
    //...
  }
}

This will still be valid:

foo foo1();

But the other line will return an error:

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

 

This error will also appear in various other cases such as trying to create a temporary copy of an object. I think that constructors which can be called with no parameters should be treated as default constructors.


No matching signatures to 'string::split(const string)'

13 August 2013 - 08:22 AM

The topic title is the error I got when I made an attempt to use the split method from inside a script. The way I call it is really nothing fancy, it looks like this:

string text="Line 1\nLine 2";
array<string> line=text.split("\n");

AngelScript manual lists it as one of methods supported by strings. It's said to be a version 2.21.0 addition along with substr, findFirst and findLast methods, all of which appear to work correctly as opposed to split.


Nameless arguments cannot have default values

03 July 2013 - 05:42 AM

I think the topic name accurately describes the problem I encountered while using AngelScript. It's not a major error, but it bothers me. For reference, C++ standard allows nameless function arguments with default values:

void foo(int=0);

AngelScript supports both nameless function arguments (foo(int)) and default values of arguments (foo(int unused=0) - currently the best substitute, but if this were C++, some compilers would generate a warning about an unused argument), but the above code is for no apparent reason considered incorrect.

 

Now I realize your first thought might be that something like this is completely useless. I already went through explaining how it can be used to my friend, whose first response was "it really feels like you should be doing whatever you're doing in another way", but who later admitted this solution would be the best one. I don't want to get into detail again; in short, it's about functions that have to fit a certain funcdef, so they support handles of that kind, but at the same time are also meant to be called from code directly.


PARTNERS