Skip to main content
Arduino

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

Required fields*

How do you call a class method with named parameters?

I have a C++ class constructor like:

Motors(int p1=0, int p2=0);

However, when I attempt to instantiate it with named parameters like:

Motors motors(p1=123, p2=456);

the Arduino C/C++ compiler gives me the errors:

src/motors.ino:3: error: ‘p1’ was not declared in this scope
src/motors.ino:3: error: ‘p2’ was not declared in this scope

The compiler doesn't seem to support named parameters and thinks I'm referring to variables. I thought named parameters was a pretty widely supported feature, even in C++. What am I doing wrong?

Answer*

Draft saved
Draft discarded
Cancel

lang-cpp

AltStyle によって変換されたページ (->オリジナル) /