lundi 26 juin 2017

Passing object to a function prior to the object defnition [duplicate]

This question already has an answer here:

class e;
//!should not be valid
void f(e);  //but it is valid (No compiler error) //:~ declaration1

//! should be valid
void f(e*); //and it is valid (No compiler error)  //:~ declaration2

I am somewhat confused why compiler doesn't give error/warning on declaration 1 because I am passing here whole object as a argument, and for that I guess, compiler must see the entire definition of that object to know the size and how to pass it, but I hadn't provided any definition.

I guess we can always use pointer to object as arg(like in declaration 2), prior to its definition because compiler always knows how to pass address regardless of any object. That's why declaration 2 is somewhat satisfying.

But passing whole object before its definition must give some warning or error but it doesn't. So what is compiler implicitly doing here?? Please help, its really confusing for me.

Aucun commentaire:

Enregistrer un commentaire