0

In C++ we have feature people do not think about much, like we can execute method of a class that uses method/member that has been declared later in class i.e.:

struct s{
 foo() { foo1();}
 foo1() { assert(0); }
 };

 int main() {
  s s1; s1.foo();
 }

I already know that compiler puts member definitions after class definition and it can be found so the order doesn't matter: Do class functions/variables have to be declared before being used?. What I was wondering is how it would look like if we would make methods inline and compiler will respect our request and make them really inline would it work then? Would compiler do any additional stuff to reorder whole class?

Community
  • 1
  • 1
Mateusz Wojtczak
  • 1,621
  • 1
  • 12
  • 28
  • 4
    I don't understand this question. Inlining in the way you mean is about code generation, not about scoping. Leave it to the compiler to be smart about that. – Kerrek SB Aug 31 '16 at 08:57
  • 1
    I love the question: "Would that work?" where the answer is "Try it and you'll see". It would have taken you less time to test it for yourself than it did to write this question. Also what KerrekSB said. – bolov Aug 31 '16 at 09:20

0 Answers0