私は、スコープを最小限にとどめています。それと、何が一番きれいなものであれ。
1つの関数に使用する場合は、その関数のスコープ内に保持します。いくつかの関数に使用する場合は、それをprivate型typedefにしてください。そして、他の人がそれを使うことを期待しているなら(おそらく実用性に欠けます)、それを公開してください。コードで
:
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;
};
うまくいけば、あなたに私が何を意味するかのアイデアを提供します。
私はあなたがなぜ尋ねているのか分かりません。聞いたことがありますか? –
ハハ、何?それは歌からですか? – SirYakalot
あなたの例にtypedefはありません... – interjay