智能感知:不能将 "void" 类型的值分配给类型 "double" 的实体
IntelliSense: a value of type "void" cannot be assigned to an entity of type "double"
因此,我删除并重新键入了错误所指的行,关闭并重新打开了Visual Studio,并查看了此处发布的几个错误,这些错误显示了与我的相同/相似的措辞。
我有一种感觉,这是Visual Studio的错误,因为即使在我删除了所有代码,保存并重新编译之后,它在同一行上给出了不再存在的错误。
"智能感知:不能将类型为"void"的值分配给类型为"double"的实体"
以防万一这不是工作室的错误,我想我会询问有关我的代码中可能导致此错误的任何想法?代码中间的块引用是它引用该错误的行。
#include <iostream>
#include <vector>
#include <string>
using namespace std;
int main ()
{
//Declarations of vectors and basic holders for input transfer
vector<string> candidateName;
string inputString;
vector<int> candidateVotes;
int counter,inputInt,totaledVotes;
double percentage;
vector<double> candidatePercentage;
//Method declaration for calculations
void calculatePercentage (int, int, int);
//User input to gather number of candidates, names, and votes received.
cout <<"How many candidates need to be input?";
cin>>counter;
for(int i = 0;i<counter;i++)
{
cout<<"Please enter the candidate's last name.";
cin>>inputString;
candidateName.push_back(inputString);
cout<<"Please enter the number of votes "<<candidateName[i]<<" received.";
cin>>inputInt;
candidateVotes.push_back(inputInt);
totaledVotes+=candidateVotes[i];
}
for(int i = 0;i<counter;i++)
{
//Problem here vvv
percentage = calculatePercentage(totaledVotes, candidateVotes[i], i);
//Problem there ^^^
candidatePercentage.push_back(percentage);
}
}
double calculatePercentage (int totalVotes, int candidateVotes, int rosterNumber)
{
int percentage;
percentage = candidateVotes/totalVotes;
percentage*=100;
return percentage;
}
你有这个声明
void calculatePercentage (int, int, int);
然后你做
percentage = calculatePercentage(totaledVotes, candidateVotes[i], i);
但是您刚刚声明该函数不返回任何内容。
而且它与后面的实际定义也不匹配:
double calculatePercentage (int totalVotes, int candidateVotes, int rosterNumber)
你声明返回void
的函数:
void calculatePercentage (int, int, int);
这应该double
,以匹配后面的定义和用法。
相关文章:
- 不能将 "void *" 类型的值分配给类型 "TCHAR" 的实体
- 需要帮助在 c++ 中将字符串转换为字符 ----错误 "const char *" 类型的值不能用于初始化 "char" 类型的实体
- 无法将错误分配给成员函数中"类型的实体"
- "const wchar_t *" 类型的值不能用于初始化类型 "const PWSTR" 的实体
- Visual Studio C++:不能使用类型为 "const wchar_t *" 的值来初始化类型为 "TCHAR *" 的实体
- 不能将 "void *" 类型的值分配给类型 "RANDOMSTRUCT *" 的实体
- 回调方法显示错误,类型为"void(*)"的值不能用于初始化类型的实体
- 智能感知:不能使用 "PVOID" 类型的值初始化 "_NtQuerySystemInformation" 类型的实体
- 不能将 "const char*" 类型的值分配给类型 "int" 的实体
- 类型值不能用于初始化类型实体
- 不能将 "const char *" 类型的值分配给类型为 "LPSTR" 的实体
- c 11申请人(e)是e命名的实体的类型
- 错误:无法将 "double*" 类型的值分配给类型 "double" 的实体
- 智能感知:不能将 "void" 类型的值分配给类型 "double" 的实体
- 值类型 const char 不能用于初始化 char* 类型的实体
- ECS实体可以有多个给定类型的组件
- "char *" 类型的值不能用于初始化类型 "char" 的实体
- "const wchar_t *" 类型的值不能用于初始化类型为 "LPCSTR" 的实体
- 如何确定Tcl_Obj是否是某种类型的 ttk:: 实体,例如 ttk:entry
- 标识派生类类型的正确方法(类型实体VS dynamic_case)