-1

I am in the process creating a game and I have a problem. When I put in a “virtual” keyword to the function constructor just stops working:(

System Windows 11, C++23

Edit: You can not use braces with a class that has virtual functions. Is there a way to not generate a definition in parent class, but define in child class?

Vlad from Moscow
  • 301,070
  • 26
  • 186
  • 335
avary
  • 1
  • 1

1 Answers1

1

You are trying to initialize an object of the class notworks as an object of an aggregate. But when a virtual function is declared then the class is not an aggregate.

From the C++ 20 Standard (9.4.2 Aggregates)

1 An aggregate is an array or a class (Clause 11) with

(1.1) — no user-declared or inherited constructors (11.4.5),

(1.2) — no private or protected direct non-static data members (11.9),

(1.3) — no virtual functions (11.7.3), and

(1.4) — no virtual, private, or protected base classes (11.7.2).

Vlad from Moscow
  • 301,070
  • 26
  • 186
  • 335