#include <iostream>
using namespace std;
int mf_option(1);
int mf_rectangle(2);
int main()
{
int mf_option(1);
int mf_rectangle(2);
return 0;
}
int mf_option(1)
{
char a;
int size = 0;
cout << "Enter a character: " << endl;
cin >> a;
while (size < 1 || size > 5)
cout << "Enter a valid size from 1-5: " << endl;
cin >> size;
}
int mf_rectangle(2)
{
int size = 0;
for (int row = 1; row <= size; row++)
{
for (int col = 1; col <= size; col++)
{
if (row > 1 && row < size && col > 1 && col < size)
cout << " ";
else
cout << a;
}
cout << "\n\n";
}
for (int row = 2; row <= size; row++)
{
for (int col = 2; col <= size; col++)
{
if (row > 2 && row < size && col > 2 && col < size)
cout << " ";
else
cout << a;
}
cout << "\n\n";
}
for (int row = 3; row <= size; row++)
{
for (int col = 3; col <= size; col++)
{
if (row > 3 && row < size && col > 3 && col < size)
cout << " ";
else
cout << a;
}
cout << "\n\n";
}
for (int row = 4; row <= size; row++)
{
for (int col = 4; col <= size; col++)
{
if (row > 4 && row < size && col > 4 && col < size)
cout << " ";
else
cout << a;
}
cout << "\n\n";
}
for (int row = 5; row <= size; row++)
{
for (int col = 5; col <= size; col++)
{
if (row > 5 && row < size && col > 5 && col < size)
cout << " ";
else
cout << a;
}
cout << "\n\n";
}
}
我不明白为什么我在第15行和第26行收到此错误。第15行也有一个错误,表示期望&#39 ;;&#39;。这是错误消息 错误1错误C2448:&#39; mf_option1&#39; :函数式初始值设定项似乎是一个函数定义
答案 0 :(得分:2)
int mf_option(1);
是变量mf_option
的定义。它的类型为int
,值为1
。它不是函数的声明。
稍后,你有:
int mf_option(1)
{
...
}
这是一个语法上无效的构造。它开始就像你要定义一个变量一样,最终就像你定义一个函数一样。
mf_rectangle
存在类似的问题。
如果我理解你的意图,你需要更换这些行:
int mf_option(1);
int mf_rectangle(2);
通过
int mf_option(int arg);
int mf_rectangle(int arg);
对尝试定义函数的位置进行类似的更改。