Error when initializing a struct with a brace-enclosed initializer list

c++, constructor, struct

Solution

Your class has a constructor, so it isn't an aggregate, meaning you cannot use aggregate initialization. You can add a constructor taking the right number and type of parameters:

struct CLICKABLE
{
  int x;
  int y;
  BITMAP* alt;
  BITMAP* bitmap;

  CLICKABLE(int x, int y, BITMAP* alt, BITMAP* bitmap) 
  : x(x), y(y), alt(alt), bitmap(bitmap) { ... }

  CLICKABLE() : x(), y(), alt(), bitmap() {}

};

Alternatively, you can remove the user declared constructors, and use aggregate initialization:

CLICKABLE a = {};         // all members are zero-initialized
CLICKABLE b = {1,2,0,0};

Problem

``` struct CLICKABLE { int x; int y; BITMAP* alt; BITMAP* bitmap; CLICKABLE() { alt=0; } }; CLICKABLE input={1,2,0,0}; ``` This code gives me the following error: Could not convert from brace-enclosed initializer list Could someone explain me why the compiler is giving me this error, and how I can fix it? I'm still learning the language.

Original source