Skip to main content
AI Assist is now on Stack Overflow. Start a chat to get instant answers from across the network. Sign up to save and share your chats.

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

4
  • You define classes in headers, so they get defined in every TU. (And Wikipedia is somewhere between misleading and wrong about parts of the ODR, too.) It's objects and (non-inline) functions that are declared in headers and defined exactly once. Commented Jan 10, 2010 at 18:03
  • What is exactly the difference between "definition" and "declaration"? Commented Jan 10, 2010 at 18:32
  • A declaration only introduces a 'signature', but the definition really refers to function or method bodies. Its true that a class can be both declared and defined in one statement, but you would normally put this in a header file. A class can also be declared in a header, leaving its method bodies to be defined in a .cpp file. Commented Jan 10, 2010 at 18:57
  • 1
    Examples: class Declaration; class Definition {}; void function_declaration(); void function_definition() {} extern int global_obj_declaration; int global_obj_definition; Commented Jan 10, 2010 at 19:02