注册 登录
编程论坛 C++教室

term does not evaluate to a function taking 4 arguments

ddflovefbk 发布于 2007-07-21 17:01, 1454 次点击

我照书上打的
#include "stdafx.h"
#include <iostream>
using namespace std;
int main()
{
//二维字符数组的声明和初始化,未被初始化的元素初始值为0:
static char diamond[][5]=((' ',' ','*'),(' ','*',' ','*'),('*',' ',' ',' ','*')
(' ','*',' ','*'),(' ',' ','*'));
int i,j;
for(i=0;i<5;i++)
{
for(j=0;j<5 && diamond[i][j]!=0;j++)
cout<<diamond[i][j];
cout<<endl;
}
}
为什么会出现 term does not evaluate to a function taking 4 arguments
这是什么意思啊?

2 回复
#2
一番宝瓶2007-07-21 17:24

因为数组赋值的时候 你写成括号"()"了,编译器就当成函数了

static char diamond[][5]={{' ',' ','*'},{' ','*',' ','*'},{'*',' ',' ',' ','*'},{' ','*',' ','*'},{' ',' ','*'}};


其实上面的程序可以写成通用的形式:


#include<cmath>
using namespace std;
const int N = 2;
int main()
{
    int i,j;
    for(i=-N; i<=N; i++, cout<<endl)
    for(j=-N; j<=N; j++)
  ( abs(i)+abs(j) == N ) ? cout<<\"*\" : cout<<\" \";
return 0;
}

#3
ddflovefbk2007-07-21 19:01

哦,原来是这样啊,谢谢了!!

1