0
class cl { 
    public:
        cl(int i) { val=i; }
        int val;
        int double_val() { return val+val; }
};

Variable val is declared after the constructor, which assigns it. But still this code works. Isn't 'val' out of scope for constructor?

DevSolar
  • 67,862
  • 21
  • 134
  • 209
  • @Downvoter, what is the reason for the downvote? This question contains [mcve], in addition to clear, and specific question. If the reason for the downvote was "no research", you could have suggested a duplicate. – Algirdas Preidžius Dec 19 '17 at 14:00

1 Answers1

4

The full definition of the class is available to its members. So val is actually declared before the constructor's implementation.

Luchian Grigore
  • 253,575
  • 64
  • 457
  • 625