class MISC
explicit
before a single parameter constructorClassName::s_member
static const T s_data
It's best to make it a non-member non-friend function, use accessor to get the data. Which means it should be defined out of the class definition. E.g.
Class A{
};
bool operator < (){}
Example
bool operator<(const Account& lhs, const Account& rhs) {
return lhs.balance() < rhs.balance(); // compare accounts by balance
}
Example:
#include <iostream>
class A {
private:
int a;
public:
A() { a=0; }
friend class B; // Friend Class
};
class B {
private:
int b;
public:
void showA(A& x) {
// Since B is friend of A, it can access
// private members of A
std::cout << "A::a=" << x.a;
}
};
int main() {
A a;
B b;
b.showA(a);
return 0;
}
Use ClassName::EnumName
to access it from outside, remember to make it public.
template <typename T>
void swap(T& x, T& y)
{
T xCopy(x);
x = y;
y = xCopy;
}