#include <iostream>
using namespace std; struct salary{
string name;
float income;
float allowance;
}; void main () {
salary workerInfo[5] = {
{"James", 2000.0, 200.0},
{"Benny", 3000.0, 300.0},
{"Marie", 4000.0, 300.0},
{"Johns", 3000.0, 500.0},
{"Jacks", 5000.0, 700.0}
};
}程序编译出错:Compiling...
exercise.cpp
E:\exercise.cpp(270) : error C2440: 'initializing' : cannot convert from 'char [6]' to 'struct salary'
No constructor could take the source type, or constructor overload resolution was ambiguous
E:\exercise.cpp(270) : error C2440: 'initializing' : cannot convert from 'const double' to 'struct salary'
No constructor could take the source type, or constructor overload resolution was ambiguous
E:\exercise.cpp(270) : error C2440: 'initializing' : cannot convert from 'const double' to 'struct salary'
No constructor could take the source type, or constructor overload resolution was ambiguous
E:\exercise.cpp(270) : fatal error C1903: unable to recover from previous error(s); stopping compilation
Error executing cl.exe.如果将"string name"改为"char name[6]"编译通过了, 请问这是怎么回事, 难道string就不能用吗 ?
请问各位.
using namespace std; struct salary{
string name;
float income;
float allowance;
}; void main () {
salary workerInfo[5] = {
{"James", 2000.0, 200.0},
{"Benny", 3000.0, 300.0},
{"Marie", 4000.0, 300.0},
{"Johns", 3000.0, 500.0},
{"Jacks", 5000.0, 700.0}
};
}程序编译出错:Compiling...
exercise.cpp
E:\exercise.cpp(270) : error C2440: 'initializing' : cannot convert from 'char [6]' to 'struct salary'
No constructor could take the source type, or constructor overload resolution was ambiguous
E:\exercise.cpp(270) : error C2440: 'initializing' : cannot convert from 'const double' to 'struct salary'
No constructor could take the source type, or constructor overload resolution was ambiguous
E:\exercise.cpp(270) : error C2440: 'initializing' : cannot convert from 'const double' to 'struct salary'
No constructor could take the source type, or constructor overload resolution was ambiguous
E:\exercise.cpp(270) : fatal error C1903: unable to recover from previous error(s); stopping compilation
Error executing cl.exe.如果将"string name"改为"char name[6]"编译通过了, 请问这是怎么回事, 难道string就不能用吗 ?
请问各位.
解决方案 »
- Error spawning 'vcspawn.exe'. The build could not be performed
- VC中在Toolbar上的各个Button,我想让每个button都能响应右键单击,
- 用ListCtrl控件 Report属性 无法显示数据
- 内存问题
- 怎样通过句柄(窗口句柄、DC句柄等)来取得对象占用的资源量?
- 还是关于IP包修改问题,我已经问两次2了,把我200分都放出去练,现在就省80了,请大家帮忙
- 怎么禁用一个存储设备(如USB)?排除修改注册表的方法
- 非模式对话框内的文字消失了
- 有关数据库的类的继承的问题,谢谢,在线等待!!
- 请问,怎样获得其他程序Edit控件的句柄?
- CAsyncSocket Create的问题
- 如何取得一个窗口的状态啊?(Enabled或Disabled)
#include "stdafx.h"
#include <iostream>
#include "string.h"
using namespace std; struct salary{
string name;
float income;
float allowance; salary(char str[6],float incomepara,float allowancepara){
string name(str);
income=incomepara;
allowance=allowancepara;
};
};
void main () {
salary workerInfo[5] = {
{James", 2000.0, 200.0},
{"Benny", 3000.0, 300.0},
{"Marie", 4000.0, 300.0},
{Johns", 3000.0, 500.0},
{"Jacks", 5000.0, 700.0}
};
}这样为什么也不可以
{string("James"), 2000.0, 200.0},
#include <iostream>
using namespace std; struct salary{
string name;
float income;
float allowance;
salary (string na, float inc, float allow) {
name = na;
income = inc;
allowance = allow;
}
}; void main () {
salary sal[2] = {
(string("James"), 2300, 340),
(string("Benny"), 3400, 450)
};
// ... ...
}报错:E:\exercise.cpp(413) : error C2440: 'initializing' : cannot convert from 'struct salary *' to 'struct salary'
No constructor could take the source type, or constructor overload resolution was ambiguous
E:\exercise.cpp(415) : error C2440: 'initializing' : cannot convert from 'struct salary *' to 'struct salary'
No constructor could take the source type, or constructor overload resolution was ambiguous
E:\exercise.cpp(415) : fatal error C1903: unable to recover from previous error(s); stopping compilation
Error executing cl.exe.
exercise.exe - 3 error(s), 0 warning(s)请好心的高手们帮帮忙!
salary(string("James"), 2300, 340),
salary(string("Benny"), 3400, 450)
};