<legend id='IYG7a'><style id='IYG7a'><dir id='IYG7a'><q id='IYG7a'></q></dir></style></legend>
        <bdo id='IYG7a'></bdo><ul id='IYG7a'></ul>

      <small id='IYG7a'></small><noframes id='IYG7a'>

    1. <i id='IYG7a'><tr id='IYG7a'><dt id='IYG7a'><q id='IYG7a'><span id='IYG7a'><b id='IYG7a'><form id='IYG7a'><ins id='IYG7a'></ins><ul id='IYG7a'></ul><sub id='IYG7a'></sub></form><legend id='IYG7a'></legend><bdo id='IYG7a'><pre id='IYG7a'><center id='IYG7a'></center></pre></bdo></b><th id='IYG7a'></th></span></q></dt></tr></i><div id='IYG7a'><tfoot id='IYG7a'></tfoot><dl id='IYG7a'><fieldset id='IYG7a'></fieldset></dl></div>

    2. <tfoot id='IYG7a'></tfoot>
    3. 如何一次将多个值分配给一个结构?

      how to assign multiple values into a struct at once?(如何一次将多个值分配给一个结构?)
      <tfoot id='8wpqs'></tfoot>

          <small id='8wpqs'></small><noframes id='8wpqs'>

            <i id='8wpqs'><tr id='8wpqs'><dt id='8wpqs'><q id='8wpqs'><span id='8wpqs'><b id='8wpqs'><form id='8wpqs'><ins id='8wpqs'></ins><ul id='8wpqs'></ul><sub id='8wpqs'></sub></form><legend id='8wpqs'></legend><bdo id='8wpqs'><pre id='8wpqs'><center id='8wpqs'></center></pre></bdo></b><th id='8wpqs'></th></span></q></dt></tr></i><div id='8wpqs'><tfoot id='8wpqs'></tfoot><dl id='8wpqs'><fieldset id='8wpqs'></fieldset></dl></div>
            <legend id='8wpqs'><style id='8wpqs'><dir id='8wpqs'><q id='8wpqs'></q></dir></style></legend>
                <tbody id='8wpqs'></tbody>

                <bdo id='8wpqs'></bdo><ul id='8wpqs'></ul>

                本文介绍了如何一次将多个值分配给一个结构?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                问题描述

                我可以在 struct Foo 的初始化时执行此操作:

                I can do this on initialization for a struct Foo:

                Foo foo =  {bunch, of, things, initialized};
                

                但是,我不能这样做:

                Foo foo;
                foo = {bunch, of, things, initialized};
                

                那么,两个问题:

                1. 为什么我不能做后者,前者是一个仅用于初始化的特殊构造函数吗?
                2. 我该如何做类似于第二个例子的事情,即在一个结构体已经初始化之后,在一行代码中为它声明一堆变量?我试图避免对具有许多变量的大型结构执行此操作:

                1. Why can't I do the latter, is the former a special constructor for initialization only?
                2. How can I do something similar to the second example, i.e. declare a bunch of variables for a struct in a single line of code after it's already been initialized? I'm trying to avoid having to do this for large structs with many variables:

                Foo foo;
                
                foo.a = 1;
                foo.b = 2;
                foo.c = 3;
                //... ad infinitum
                

                推荐答案

                第一个是聚合初始值设定项 - 您可以在此解决方案中阅读这些和标记初始值设定项:

                The first is an aggregate initializer - you can read up on those and tagged initializers at this solution:

                什么是标记结构初始化语法?

                这是一种特殊的初始化语法,在你的结构初始化之后你不能做类似的事情.您可以做的是提供一个成员(或非成员)函数来将您的一系列值作为参数,然后您在成员函数中分配这些参数 - 这将允许您在结构以同样的方式初始化后完成此操作简洁(当然是在您第一次编写函数之后!)

                It is a special initialization syntax, and you can't do something similar after initialization of your struct. What you can do is provide a member (or non-member) function to take your series of values as parameters which you then assign within the member function - that would allow you to accomplish this after the structure is initialized in a way that is equally concise (after you've written the function the first time of course!)

                这篇关于如何一次将多个值分配给一个结构?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                相关文档推荐

                How to print vector#39;s data(如何打印矢量的数据)
                Visual C++ appends 0xCC (int3) bytes at the end of functions(Visual C++ 在函数末尾附加 0xCC (int3) 字节)
                How to use a variable inside a _T wrapper?(如何在 _T 包装器中使用变量?)
                MSVC++ warning flags(MSVC++ 警告标志)
                How to read file which contains uxxxx in vc++(如何在vc++中读取包含uxxxx的文件)
                stack overflow error in C++ program(C++程序中的堆栈溢出错误)
              • <tfoot id='Z6fNC'></tfoot>

                <legend id='Z6fNC'><style id='Z6fNC'><dir id='Z6fNC'><q id='Z6fNC'></q></dir></style></legend>
              • <i id='Z6fNC'><tr id='Z6fNC'><dt id='Z6fNC'><q id='Z6fNC'><span id='Z6fNC'><b id='Z6fNC'><form id='Z6fNC'><ins id='Z6fNC'></ins><ul id='Z6fNC'></ul><sub id='Z6fNC'></sub></form><legend id='Z6fNC'></legend><bdo id='Z6fNC'><pre id='Z6fNC'><center id='Z6fNC'></center></pre></bdo></b><th id='Z6fNC'></th></span></q></dt></tr></i><div id='Z6fNC'><tfoot id='Z6fNC'></tfoot><dl id='Z6fNC'><fieldset id='Z6fNC'></fieldset></dl></div>
                    <bdo id='Z6fNC'></bdo><ul id='Z6fNC'></ul>

                            <tbody id='Z6fNC'></tbody>

                          <small id='Z6fNC'></small><noframes id='Z6fNC'>