他们称这种构造函数为何? [英] What do they call this kind of constructor?
问题描述
是否有一个构造函数的特殊名称,它可以执行类似结构的
初始化?示例:
类DefaultCtor
{
std :: string class_name;
bool compiler_generated;
public:
DefaultCtor(std :: string class_name,bool compiler_generated);
};
DefaultCtor :: DefaultCtor(std :: string class_name_,bool compiler_generated_)
:class_name(class_name_),compiler_generated(compiler_generated_)
{
}
谢谢。
Jason Heyes写道:< blockquote class =post_quotes>构造函数是否有一个特殊的名称来进行类似结构的初始化?
什么是'struct-like initialisation" ;?
示例:
类DefaultCtor
{
std :: string class_name;
bool compiler_generated;
public:
DefaultCtor(std :: string class_name,bool compiler_generated);
DefaultCtor :: DefaultCtor(std :: string class_name_,bool compiler_generated_)
:class_name(class_name_),compiler_generated(compiler_generated_)
}
blockquote>
这里有一个普通的_parameterized_构造函数。它是
*绝对*不是''默认'',所以有一个用词不当。
另外,作为附注,你不应该'按值传递''std :: string'',
没有值(双关语)。你应该把它传给
给const:
SomeCtor(std :: string const& class_name,...
>
V
" Victor Bazarov" v。******** @ comAcast.net>写在消息中
news:jT ****************** @ newsread1.mlpsca01.us.to .verio.net ...Jason Heyes写道:是否有一个特殊的名称,构造函数进行类似结构的
初始化?
什么是结构初始化"?
示例:
类DefaultCtor
{st / :: string class_name;
bool compiler_generated;
public:
DefaultCtor(std :: string class_name,bool compiler_generated);
};
DefaultCtor :: DefaultCtor(std: :string class_name _,bool
compiler_generated_):class_name(class_name_),
compiler_generated(compiler_generated _)
{
}
这里有一个普通的_parameterized_构造函数。它绝对不是''默认'',所以有一个用词不当。
另外,作为旁注,你不应该通过''std: :字符串''按值,
没有值(双关语)。你应该将它传递给const
SomeCtor(std :: string const& class_name,...
V
我将其称为带参数的默认构造函数或默认
参数化构造函数。这听起来怎么样?
当我知道它不会影响
性能时,我不会通过const引用传递std :: string。
Jason Heyes写道:" Victor Bazarov" v。******** @ comAcast.net> ;写在消息中
新闻:jT ****************** @ newsread1.mlpsca01.us.to .verio.net ...Jason Heyes写道:是否有一个构造函数的特殊名称,它可以进行类似结构的初始化?
什么是& ; struct-like initialisation"?
示例:
class Def aultCtor
{
std :: string class_name;
bool compiler_generated;
public:
DefaultCtor(std :: string class_name,bool compiler_generated); <默认值为:: DefaultCtor :: DefaultCtor(std :: string class_name_,bool
compiler_generated_):class_name(class_name_),
compiler_generated(compiler_generated _)
{
}
这里有一个普通的_parameterized_构造函数。它绝对不是''默认'',所以有一个用词不当。
另外,作为旁注,你不应该通过''std: :字符串''按值,
没有值(双关语)。你应该将它传递给const
SomeCtor(std :: string const& class_name,...
V
我将其称为带参数的默认构造函数或默认的
参数化构造函数。这听起来怎么样?
您提供了它,因此它不是默认构造函数。
在您看来,非默认参数化构造函数看起来如何
like ?
谢谢,
Dan
Is there a special name for a constructor that does struct-like
initialisation? Example:
class DefaultCtor
{
std::string class_name;
bool compiler_generated;
public:
DefaultCtor(std::string class_name, bool compiler_generated);
};
DefaultCtor::DefaultCtor(std::string class_name_, bool compiler_generated_)
: class_name(class_name_), compiler_generated(compiler_generated_)
{
}
Thanks.
Jason Heyes wrote:Is there a special name for a constructor that does struct-like
initialisation?
What''s a "struct-like initialisation"?
Example:
class DefaultCtor
{
std::string class_name;
bool compiler_generated;
public:
DefaultCtor(std::string class_name, bool compiler_generated);
};
DefaultCtor::DefaultCtor(std::string class_name_, bool compiler_generated_)
: class_name(class_name_), compiler_generated(compiler_generated_)
{
}
What you have here is a normal _parameterized_ constructor. It is
*definitely* not a ''default'' one, so there is a misnomer.
Also, as a side note, you shouldn''t be passing ''std::string'' by value,
there is no value in that (pun intended). You should pass it by a ref
to const:
SomeCtor(std::string const& class_name, ...
V
"Victor Bazarov" <v.********@comAcast.net> wrote in message
news:jT******************@newsread1.mlpsca01.us.to .verio.net...Jason Heyes wrote:Is there a special name for a constructor that does struct-like
initialisation?
What''s a "struct-like initialisation"?Example:
class DefaultCtor
{
std::string class_name;
bool compiler_generated;
public:
DefaultCtor(std::string class_name, bool compiler_generated);
};
DefaultCtor::DefaultCtor(std::string class_name_, bool
compiler_generated_) : class_name(class_name_),
compiler_generated(compiler_generated_)
{
}
What you have here is a normal _parameterized_ constructor. It is
*definitely* not a ''default'' one, so there is a misnomer.
Also, as a side note, you shouldn''t be passing ''std::string'' by value,
there is no value in that (pun intended). You should pass it by a ref
to const:
SomeCtor(std::string const& class_name, ...
V
I will call it a "default constructor that takes arguments" or a "default
parameterized constructor." How does that sound?
I don''t pass std::string by const reference when I know it won''t affect
performance.
Jason Heyes wrote:"Victor Bazarov" <v.********@comAcast.net> wrote in message
news:jT******************@newsread1.mlpsca01.us.to .verio.net...Jason Heyes wrote:Is there a special name for a constructor that does struct-like
initialisation?
What''s a "struct-like initialisation"?Example:
class DefaultCtor
{
std::string class_name;
bool compiler_generated;
public:
DefaultCtor(std::string class_name, bool compiler_generated);
};
DefaultCtor::DefaultCtor(std::string class_name_, bool
compiler_generated_) : class_name(class_name_),
compiler_generated(compiler_generated_)
{
}
What you have here is a normal _parameterized_ constructor. It is
*definitely* not a ''default'' one, so there is a misnomer.
Also, as a side note, you shouldn''t be passing ''std::string'' by value,
there is no value in that (pun intended). You should pass it by a ref
to const:
SomeCtor(std::string const& class_name, ...
V
I will call it a "default constructor that takes arguments" or a "default
parameterized constructor." How does that sound?
You provided it, therefore it is NOT a default constructor.
In your opinion, how a non-default parametrized constructor would look
like?
Thanks,
Dan
这篇关于他们称这种构造函数为何?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!