【问题标题】:Visual Studio: structures: error C2440Visual Studio:结构:错误 C2440
【发布时间】:2014-10-23 20:01:44
【问题描述】:

拜托,我正在寻求帮助,我已经绝望了。

这是我的代码:

#include <stdlib.h>
#include <stdio.h>



typedef struct {
   int citatel, jmenovatel;
} Zlomek;

typedef struct {
    Zlomek j, c;
} Slozeny;


int main()
{
      Zlomek z1 = {2, 5}, z2 = {3, 7};
      Slozeny slozenec = {z1, z2};

      system("PAUSE");
      return 0;
 }

当我编译时,VS 只是抛出:错误 C2440: 'initializing' : cannot convert from 'Zlomek' to 'int'。有人可以帮帮我吗?

【问题讨论】:

  • VS 哪个版本?我在 VS2010(终极版)中制作了一个控制台 win32 应用程序,并将您的代码放入自动生成的 .cpp 文件中。在我将int main() 更改为int _tmain(int argc, _TCHAR* argv[]) 后,它编译时没有发出呜咽声

标签: c debugging structure


【解决方案1】:

您的旧编译器无法使用非常量执行初始化。

使用更新的编译器或替换

  Slozeny slozenec = {z1, z2};

通过

  Slozeny slozenec ;
  slozenec.j = z1 ;
  slozenec.c = z2 ;

【讨论】:

    猜你喜欢
    • 2021-01-08
    • 2016-01-11
    • 2021-04-16
    • 1970-01-01
    • 1970-01-01
    • 2011-11-20
    • 2018-12-03
    • 2022-01-24
    相关资源
    最近更新 更多