Problem of the default parameters.

xiaoxiao2021-04-10  375

Today, I saw a question of a default parameter on 9CBS. I was scared, I used to explain this question like this netizen. I tried it several times in DEV C , I finally got the answer.

Posts: http://community.9cbs.net/expert/topic/4841/4841909.xml? Temp = .3743402

The problem is probably: C Primer: "The subsequent declaration of the class template can provide additional default arguments for the template parameters. As the default argument of the function parameters. Before the parameters of the function parameters provide default arguments It must first provide default arguments to the rightmost parameters that are not initialized. "

So write the following verification program: #include using namespace std;

Template Class Foo {Public: T A; C B;

// Subsequent declaration provides additional default arguments (but since the template parameter C has no default, it should be wrong) Template Class Foo;

INT main () {return 0;}

My understanding is this:

The template is a model used two compiled models, and the first check is the basic syntax structure of the template. The second time is the constructor for parameters.

C specifies that the default parameters of the template parameters are instantiated when they are used. The default parameter is defined when the lexic check and the name lookup.

The problem may be wrong to understand the book.

"The subsequent declaration of the class template can provide additional default arguments for the template parameters. As the default argument of the function parameters, the right side must be initialized before the default stream is provided to the left. The parameters provide default arguments. "

I estimate that "Before providing default in-arguments to the left, you must first provide default arguments to the rightmost parameters." This sentence translates the problem.

I will give you an example:

Template class foo; template Class foo; foo <> C; the program is not prompted. Template class foo; template // program error in this class foo; foo <> C;

Another example: template class foo; template Class foo; foo C;

Template Class Foo; Template Class Foo; Foo C;

My personal summary is this: The default parameter can be defined in each declaration, but it is not allowed to define the same parameter (even if the same instance) is actually used, all the default parameters must be on the right side of the expression. There is no interval between the default parameters used.

转载请注明原文地址:https://www.9cbs.com/read-133479.html

New Post(0)