C++

The most vexing parse

Në shqip: „Leximi më bezdisës“

ShpjegimiSQ

Lojtar l(); duket sikur krijon një objekt, por kompajleri e lexon si deklarim funksioni që kthen Lojtar! Prandaj në C++ modern preferohet Lojtar l{}; me kllapa gjarpër.

EnglishEN

Player p(); looks like it creates an object, but the compiler reads it as declaring a function returning Player! That's why modern C++ prefers Player p{}; with curly braces.

Si ta mendosh

Si një fjali që mund të lexohet në dy mënyra, dhe kompajleri zgjedh gabimin.

Lexoje në anglisht

Like a sentence with two readings, and the compiler picks the wrong one.

Shembull kodicpp

Lojtar a();   // ✗ deklarim funksioni!
Lojtar b{};   // ✓ objekt

Terma të lidhur