1
class Button {
public:
    Button(int pin, int debounce)
    {
    }
};
class TransferTable {
private:
    Button a(1, 1);
public:
    TransferTable()
    {
    }
};

The above code gives me an error of "expected identifier before numeric constant" in reference to the "Button a(1,1)" line. The type is Button. I just want to construct a button object within this TransferTable class.

1
  • 1
    I assume you meant public: instead of public; so I will fix this typo. Commented Jun 28, 2016 at 16:57

2 Answers 2

4

The default member initializer syntax requires the use of curly braces:

private:
Button a{1,1};

Or, you can use the "equal-syntax" to do the same thing, as pointed out by juanchopanza:

private:
Button a = Button(1, 2);

Or, if you cannot rely on C++11, you must use the member initialization list instead.

Sign up to request clarification or add additional context in comments.

1 Comment

Or the verbose alternative, Button a = Button(1, 2); which allows both round and curly braces.
1
class Button
{
public:
  Button(int pin, int debounce)
  {

  }
};

class TransferTable
{
public:
  TransferTable() : a(1, 1)
  {

  }
private:
  Button a;
};

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.