Yalnızca kapsamı minimumda tutmalıyım; Bununla, temiz olan her şeyi yapın.
Tek bir işlev için kullanırsanız, bu işlevin kapsamında tutun. Birkaç işlev için kullanırsanız, özel bir yazım yapın. Ve eğer başkalarının bunu kullanmasını beklerseniz (yardımcı programın dışında), bunu herkese açık hale getirin. kodunda
:
namespace detail
{
// By convention, you aren't suppose to use things from
// this namespace, so this is effectively private to me.
typedef int* my_private_type;
}
void some_func()
{
// I am allowed to go inside detail:
detail::my_private_type x = 0;
/* ... */
}
void some_other_func()
{
// I only need the typedef for this function,
// so I put it at this scope:
typedef really::long::type<int>::why_so_long short_type;
short_type x;
/* ... */
}
typedef int integer_type; // intended for public use, not hidden
integer_type more_func()
{
return 5;
}
class some_class
{
public:
// public, intended for client use
typedef std::vector<int> int_vector;
int_vector get_vec() const;
private:
// private, only for use in this class
typedef int* int_ptr;
};
Umarım bu size ne demek istediğimi bir fikir verir.
Sanırım neden soruyorsun anlamıyorum. Bir şey duydun mu? –
haha, ne? Bu bir şarkıdan mı? – SirYakalot
Örneğinizde yazım hatası yok ... – interjay