-1
嗨我有一个问题,使用struct
作为参数。结构作为参数导致“形式参数列表不匹配”
我的结构看上去如下:
typedef struct temps {
string name;
float max;
} temps;
我可以在我的主要使用它没有像问题:
temps t;
t.max = 1.0;
但在一个函数签名使用这样的:
void printTemps(const temps& t) {
cout << t.name << endl << "MAX: " << t.max << endl;
}
它给了我下面的编译器消息:
错误C2563:不匹配形式参数列表
这里是一个兆瓦:
#include <iostream>
#include <fstream>
#include <string>
#include <windows.h>
#include <Lmcons.h>
using namespace std;
typedef struct temps {
string name;
float max;
} temps;
void printTemps(const temps& t) {
cout << t.name << endl << "MAX: " << t.max << endl;
}
int main(int argc, char **argv)
{
temps t;
t.max = 1.0;
printTemps(t);
}
任何想法,什么是错的结构?
不要在C++中使用typedef结构。显示编译器错误消息。 – 2017-07-18 21:40:18
您使用了哪些标题和使用语句?请发布完整[mcve]。 – wally
我把'#include'和'using namespace std;'放在最上面,它在g ++ 6.3.0上编译得很好, –
Luke