小编Cra*_*kie的帖子

为什么我们不能使用 std::initializer_list 对象来初始化数组?

请首先考虑以下示例:

#include <iostream>
#include <initializer_list>
#include <vector>
#include <array>
#include <set>

int main(){
   std::initializer_list il1={1,2,3,4,5}; 
   std::initializer_list il2{1,2,3,4,5}; 
                                    
    std::vector<int> v1 = il1;  //this work - by means of COPY 
    std::set<int> s1 = il1;     //this work - by means of COPY

    std::array<int, 5> a1 = {1,2,3,4,5};  //this work
    std::array<int, 5> a2 = il1;      //this didn't work? - not compatable ?
    int array1[5] = {1,2,3,4,5};          //this work
    int array2[5] = il2;              //this didn't work? - not compatable ?                               
}
Run Code Online (Sandbox Code Playgroud)

为什么我们不能使用 std::initializer_list 的对象来初始化示例中的数组?

我收到此错误: …

c++

6
推荐指数
1
解决办法
132
查看次数

下面使用“typename”有什么区别?

typename在函数的返回类型之前使用“”与在函数声明中不使用它(如下所示)有什么区别?

如果我们根本不使用它,会有什么不同呢?

template< class T > typename std::remove_reference<T>::type&& move( T&& t );
template< class T > std::remove_reference_t<T>&& move( T&& t ) ;
Run Code Online (Sandbox Code Playgroud)

c++ templates return-type typename function-templates

2
推荐指数
1
解决办法
118
查看次数

结构体或类的实例可以被视为变量吗?

我读了:

\n
    \n
  • 变量是内存位置的名称。
  • \n
  • 在 C++ 中,变量实际上只是保留给程序\xe2\x80\x99 使用的一点内存。\n( https://en.cppreference.com/book/intro/variables )
  • \n
  • 变量名是标识符。标识符是 C++ 中用于各种事物的标签,包括函数、类、命名空间以及变量。
  • \n
\n

(意味着变量名只是标识符的一种情况)

\n

在标准 C++ 术语中,我们可以将结构体或类的实例名称视为变量吗?或者我们应该只称其为“标识符”吗?

\n

我知道这绝对是一个菜鸟问题,但即使我尝试从多个来源读取变量的定义,我自己也确实无法回答这个问题。请帮忙。

\n

c++ variables

2
推荐指数
1
解决办法
188
查看次数