Difference between auto, var and attr


Hello, I have a question.

What’s the difference between auto, var and attr keywords?


auto and var are the same. attr is only used for specifying class attributes.

var was the first keyword supported. auto was added later to allow users comfortable with C++11 to use the same keyword.

attr is used like this:

def MyClass::MyClass() {}
attr MyClass::myAttribute;

If you are using the new class keyword to define your classes, you can use any of the 3:

class MyClass
  MyClass() {}
  var myAttr;
  auto myAttr2;
  attr myAttr3;

See here:


For test cases with examples.


Thanks for a quick answer!

Actually, I’ve seen these examples before, but thought there is some hidden semantic difference between auto and var.

Are there any reasons why this page doesn’t mention auto?


Because it’s very hard to keep documentation up to date. Much harder than actually implementing the features.

I’ve updated the doxygen docs and pushed them up to the website. Unfortunately doxygen changed some fof the html filenames, so the new location is: http://chaiscript.com/docs/5/LangKeywordRef.html

Be sure to post some information about your project here Project Announcements!



Oh, ok, I understand. Thanks a lot for your help :slight_smile:

I’ll do this as soon as it will be ready.