Which is used to define the member of a class externally? a. : b. :: c. # d. !!$
时间: 2024-03-18 08:40:17 浏览: 100
b. ::
The scope resolution operator `::` is used to define a member of a class externally in C++. This allows the definition of a member function or a static data member to be separate from its declaration in the class definition.
For example:
```
class MyClass {
public:
void myFunction(); // declaration
static int myStaticVariable; // declaration
};
// definition of myFunction
void MyClass::myFunction() {
// function body
}
// definition of myStaticVariable
int MyClass::myStaticVariable = 0;
```
In the example above, `myFunction` and `myStaticVariable` are declared in the class definition, but their definitions are provided externally using the scope resolution operator `::`. This allows the implementation of the member functions and static data members to be separated from the class definition, which can make the code easier to manage and understand.
阅读全文