How to add a member to a ...
- How to add a member to a namespace:
- Navigate to the namespace.
- In the "My 'non-member's are:" association, click "New".
- Create the new member.
- How to add a member to a class:
- Navigate to the class.
- In the "My 'member's are:" association, click "New".
- Create the new member.
- How to add a member to a compound statement:
- Navigate to the compound statement.
- In the "My 'compound statement member's are:" association, click "New".
- Create the new member.
- How to add a member to a header file:
- Preprocessor directives are not owned by a scope, they are owned by a header file.
- If the member is a preprocessor directive:
- Navigate to the header file that will own the new member.
- In the "My 'header file preprocessor directive's are" association, click "New".
- Create the new preprocessor directive.
- The header file will have the new preprocessor directive in its "My 'header file member's are" association.
- The new preprocessor directive will have the header file in its "My 'owner' is:" association.
- Else:
- Navigate to the scope that will own the new member.
- Create the new member.
- In the "My 'header file's are" association, click "Add to header file".
- Select the header file.
- The header file will have the new member in its "My 'header file member's are" association.
- The new member will have the header file in its "My 'header file's are:" association.
- How to add a member to a source file (and NOT to a header file):
- Preprocessor directives are not owned by a scope, they are owned by a source file.
- If the member is a preprocessor directive:
- Navigate to the source file that will own the new member.
- In the "My 'source file preprocessor directive's are" association, click "New".
- Create the new preprocessor directive.
- The source file will have the new preprocessor directive in its "My 'source file member's are" association.
- The new preprocessor directive will have the source file in its "My 'owner' is:" association.
- Else:
- Navigate to the scope that will own the new member.
- Create the new member.
- In the "My 'source file' is" association, click "Change".
- Select the source file.
- The source file will have the new member in its "My 'source file member's are" association.
- The new member will have the source file in its "My 'source file' is:" association.
Why would you ever want to add a member to a source file and not to a header file?
One reason might be to implement an Opaque Data Type
or an Opaque Pointer.
If you want to end up with this code:
// main.cpp
#include "foo.h"
int main()
{
foo a_foo;
a_foo.bar();
return 0;
} // function body
==================
// foo.h
#ifndef FOO_IS_INCLUDED
#define FOO_IS_INCLUDED
/* concrete */ class foo_impl;
/* concrete */ class foo
{
public:
foo();
~foo();
void bar();
private:
foo_impl * my_impl;
}; // class foo
#endif // FOO_IS_INCLUDED
==================
// foo.cpp
#include "foo.h"
/* concrete */ class foo_impl
{
public:
void bar();
}; // class foo_impl
void foo_impl::bar()
{
} // function body
foo::foo()
: my_impl{new foo_impl{}}
{
} // function body
foo::~foo()
{
delete my_impl;
} // function body
void foo::bar()
{
my_impl->bar();
} // function body
then you would:
- add the foo class to the Outermost Scope,
- add the foo class to the header file named "foo" as a "header file member",
- add the declaration of the foo_impl class to the Outermost Scope,
- add the declaration of the foo_impl class to header file named "foo" as a "header file member",
- add the foo_impl class to the Outermost Scope,
- add the foo_impl class to the to the header file named "foo" as a "source file member".