Skip to content

Instantly share code, notes, and snippets.

@jatinganhotra
Created November 25, 2012 18:50
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jatinganhotra/4144783 to your computer and use it in GitHub Desktop.
Save jatinganhotra/4144783 to your computer and use it in GitHub Desktop.
Use forward declarations in C++ in all the following cases:
class Master {
private:
// Declare a member to be a pointer or a reference to the incomplete type
Forward *ptr1;
Forward &ptr2;
public:
// Declare functions or methods which accepts/return incomplete types:
void ByValue(Forward by_value);
Forward OrReturnValue();
// Define functions or methods which accepts/return pointers/references
// to the incomplete type (but without using its members):
void OrByPointer(Forward* by_pointer);
void OrByReference(const Forward& by_reference);
Forward& ReturnByRef();
Forward* ReturnByPointer();
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment