我今天学习了 C++ 11 非常有用的新特性,它允许在类声明中直接初始化数据成员:
class file_name
{
public:
file_name(const char *input_file_name);
~file_name();
private:
char *file_name=nullptr; //data_member is initialized to nullptr;
char *Allocator(int buffer_size); //code to dynamically allocate requested
//size block of memory.
};
是否可以使用新的 v11 规则更进一步,并使用成员函数的输出初始化数据成员:
class file_name
{
public:
file_name(const char *input_file_name);
~file_name();
private:
char *file_name=Allocator(MAX_PATH); //data_member is initialized with a block of
//dynamic memory of sufficient size to hold
//and valid file name.;
char *Allocator(int buffer_size); //code to dynamically allocate requested
//size block of memory.
};
这会导致问题吗?