C++ 结构和"expected primary-expression"错误
c++ struct and "expected primary-expression" error
用一些代码更容易解释:
#include <iostream>
using namespace std;
struct test {
int one;
int two;
};
void insertdata(test & info)
{
cin >> info.one;
cin >> info.two;
}
int doitnow(test mytable[])
{
test info;
int i = 0;
for (i=0; i<3; i++) {
insertdata(test & info);
mytable[i] = info;
}
return i;
}
int main()
{
int total;
test mytable[10];
total = doitnow(test mytable[]);
cout << total;
}
因此,我需要通过引用函数insertdata来传递信息,我需要在doitnow中使用该函数来填充一个表,并且我需要在主函数中显示在doitow中插入的项目数。当我尝试调用函数时,我总是会出错:
teste.cpp: In function ‘int doitnow(test*)’:
teste.cpp:21:29: error: expected primary-expression before ‘&’ token
insertdata(test & info);
teste.cpp: In function ‘int main()’:
teste.cpp:33:30: error: expected primary-expression before ‘mytable’
total = doitnow(test mytable[]);
所以,这可能是一个明显的错误,但我是这方面的初学者。
谢谢你的帮助。
-
test& info
是定义。如果将某些内容传递给函数,则编写一个类似info
的表达式。它是通过引用自动传递的,因为您在形式参数列表中指定了info
作为引用。你还写了
mytable[i] = info;
而不是
mytable[i] = test & info;
不是吗?
请改用
insertdata(info);
。 -
数组也是如此。请改用
doitnow(test)
。
相关文章:
- 为什么我的功能在使用 goto 时会给我带来"expected primary-expression before '}' token"?
- 如何将QTime保存在SQL Server Express表中并读回?
- 双线程应用比单线程应用慢 C++ (VC++ 2010 Express).如何解决?
- 如何修复此错误"expected primary expression before 'int'"?
- 使用结构和数组时的"expected primary expression before '.' token"
- VS Express 无法正确编译代码(?
- VS Express 2015 Win10 应用程序 - ifstream 无法打开文件
- C Visual Studio 2012 Express命令窗口怪异行为
- 在Visual Studio Express 2015中的同一项目中混合使用c ++和c#
- 我的C 程序在CodeBlocks中提供了正确的结果,但在Visual Basic 2005 Express Edi
- LNK1107 opengl32.dll in Visual Studio Express 2015
- 推导模板类重载方法的地址会导致"error: expected primary-expression before ‘decltype’"
- "error: expected primary-expression before '<=' token" 我做错了什么?
- "expected primary expression __"是什么意思?
- 模板成员函数调用 -- "error: expected primary-expression before 'int'"
- C++ (2012 Express) CString Issues
- OpenCV 2.4.8 Microsoft Visual C 2010 Express中的代码错误
- Visual Studio Express 2012 中的"dll not found"错误
- 在VIsual studio 2010 express中使用GLEW,SDL和OpenGL的未解析外部符号
- Visual Studio 2012 Express 编译器未正确链接头文件