佳礼资讯网

 找回密码
 注册

ADVERTISEMENT

查看: 1109|回复: 18

C++问题!!!!1

[复制链接]
发表于 9-8-2008 07:41 PM | 显示全部楼层 |阅读模式
ProgrammingAssignment2.c
C:\Users\BibuBibu\Desktop\Programming Assignment 2\ProgrammingAssignment2.c(120) : error C2063: 'origin' : not a function
C:\Users\BibuBibu\Desktop\Programming Assignment 2\ProgrammingAssignment2.c(121) : error C2063: 'destination' : not a function
Error executing cl.exe.




























》origin=origin();
        destination=destination();



什么鬼来的??
回复

使用道具 举报


ADVERTISEMENT

发表于 9-8-2008 07:50 PM | 显示全部楼层

回复 1# 超级变态龙 的帖子

把你的code放出来看看。
回复

使用道具 举报

发表于 9-8-2008 07:50 PM | 显示全部楼层
这个嘛。。。我也不懂。。。
是不是function...或者head function错误呢?
回复

使用道具 举报

发表于 9-8-2008 08:40 PM | 显示全部楼层
原帖由 超级变态龙 于 9-8-2008 07:41 PM 发表
ProgrammingAssignment2.c
C:\Users\BibuBibu\Desktop\Programming Assignment 2\ProgrammingAssignment2.c(120) : error C2063: 'origin' : not a function
C:\Users\BibuBibu\Desktop\Programming Assignment 2\ ...


你的 origin 到底素不素 function 乃的 ???
要表 void 一下 ???
回复

使用道具 举报

发表于 10-8-2008 09:01 AM | 显示全部楼层
origin=origin();
destination=destination()

variable 与 function 同名??
将variable 的名换掉, 不可与function的名相同
回复

使用道具 举报

 楼主| 发表于 10-8-2008 12:33 PM | 显示全部楼层
原帖由 onlylonly 于 10-8-2008 09:01 AM 发表
origin=origin();
destination=destination()

variable 与 function 同名??
将variable 的名换掉, 不可与function的名相同



ei !!!!!!!!!!!!!!!你怎么知道的!?!?!?


为什么不可以同名的??

老师没有说过不可以同名。。。

惨。。又写了一大堆用origin 和 destination
as  varible 的 code...
回复

使用道具 举报

Follow Us
 楼主| 发表于 10-8-2008 12:37 PM | 显示全部楼层
char origin() //function declaration for ORIGIN
{
        char origin;

        //request The user to enter the station they start from
        printf("\n\n------------------WELCOME TO THE KTAR HIGH TECHNOLOGY LRT SYSTEM----------------\n\n";
        printf("\nDear Passenger, Please Enter The Station Where You Want To Start Your Ride: \n";
        origin=toupper(getchar());  //get the character and change it to upper case
        fflush(stdin);

        return origin;

}


char destination()//Function Declaration for Destination
{
        char destination;

        //request the user to enter the station where it's his/her destination
        printf("\nDear Passenger,Please Enter The Station You Want To Go: \n";
        destination=toupper(getchar()); // get the character and change it to upper case
        fflush(stdin);

        return destination;
}


这个上面的 stament 可以走。。


下面我再另一个。。。

FUNCTION  里面


void addition()
{
   char origin,destination
    origin=origin()
    destination=destination()

的时候却走不了
回复

使用道具 举报

 楼主| 发表于 10-8-2008 12:46 PM | 显示全部楼层
原帖由 超级变态龙 于 10-8-2008 12:37 PM 发表
char origin() //function declaration for ORIGIN
{
        char origin;

        //request The user to enter the station they start from
        printf("\n\n------------------WELCOME TO THE KTAR HIGH TECHNOLOGY LRT SY ...





char origin() //function declaration for ORIGIN
{
        char origin;

        //request The user to enter the station they start from
        printf("\n\n------------------WELCOME TO THE KTAR HIGH TECHNOLOGY LRT SYSTEM----------------\n\n";
        printf("\nDear Passenger, Please Enter The Station Where You Want To Start Your Ride: \n";
        origin=toupper(getchar());  //get the character and change it to upper case
        fflush(stdin);

        return origin;

}



理应上。。
我deClare and definition 都有了。。


origin and destination function 里面

也放了相同的名字的 variable也是可以走啊。。。

可是在其他function为什么不可以走。。

[ 本帖最后由 超级变态龙 于 10-8-2008 12:49 PM 编辑 ]
回复

使用道具 举报


ADVERTISEMENT

发表于 10-8-2008 03:41 PM | 显示全部楼层

回复 8# 超级变态龙 的帖子

凡是名字不要一样,以免自找不必要的麻烦。
回复

使用道具 举报

发表于 10-8-2008 07:57 PM | 显示全部楼层

回复 8# 超级变态龙 的帖子

重点是, variable 不可以 assign 去 相同名字的function (gcc 是如此, 其他compiler 我不懂)

  1. int something()
  2. {
  3.      int something = other() // 可以
  4.      return something;
  5. }
复制代码
  1. int something()
  2. {
  3.      int something = something() // 不可以
  4.      return something;
  5. }
复制代码
不过无论如何, variable 与 function 不要同名( 理解code, debug 时会方便很多。 尤其是你看其他programmer的code时。养成好的coding style 的习惯很重要 )

[ 本帖最后由 onlylonly 于 10-8-2008 07:59 PM 编辑 ]
回复

使用道具 举报

发表于 11-8-2008 12:34 AM | 显示全部楼层
原帖由 超级变态龙 于 10-8-2008 12:33 PM 发表



ei !!!!!!!!!!!!!!!你怎么知道的!?!?!?


为什么不可以同名的??

老师没有说过不可以同名。。。

惨。。又写了一大堆用origin 和 destination
as  varible 的 code...
老师有说
是你没注意
回复

使用道具 举报

发表于 11-8-2008 08:05 AM | 显示全部楼层
原帖由 维也纳的咖啡厅 于 11-8-2008 12:34 AM 发表
老师有说
是你没注意


你跟他同班的?
回复

使用道具 举报

发表于 11-8-2008 04:51 PM | 显示全部楼层
原帖由 nayiq 于 11-8-2008 08:05 AM 发表


你跟他同班的?
cert的老师都有说过
variables cannot include
keyword,start with number,no special symbol,no space
他是diploma的
老师不会以为他们都懂了而没说吧?
第一堂课应该会说的
回复

使用道具 举报

发表于 11-8-2008 07:35 PM | 显示全部楼层

回复 13# 维也纳的咖啡厅 的帖子

origin 的确不是keyword, 也不是start with no, 也没有 special symbol, 没空个。

无论理论实际上都没错, (在 gcc 里是如此)

只不过身为programmer 非常不推荐这种写法罢了。
回复

使用道具 举报

发表于 11-8-2008 09:55 PM | 显示全部楼层
lecturer未必會說的囉.....
回复

使用道具 举报

发表于 12-8-2008 01:59 AM | 显示全部楼层
原帖由 onlylonly 于 11-8-2008 07:35 PM 发表
origin 的确不是keyword, 也不是start with no, 也没有 special symbol, 没空个。

无论理论实际上都没错, (在 gcc 里是如此)

只不过身为programmer 非常不推荐这种写法罢了。
受教了
谢谢

原帖由 cheng1986 于 11-8-2008 09:55 PM 发表
lecturer未必會說的囉.....

对不起
可能你们lecturer以为你们会了
对不起
回复

使用道具 举报


ADVERTISEMENT

发表于 12-8-2008 12:01 PM | 显示全部楼层
你不应该把variable name 设为和 function name 一样是因为 function pointer:

int some_name(int arg)
{
...//some function operations...
}
void *pointer = some_name; //pointer now point to a function
pointer(5); //<--calling function by pointer, same as calling some_name(5);

这会和

int value = 100;
int *some_name = &value;
pointer = some_name; //pointer now point to an INT address

造成冲突, 因为compiler无法判断,你的void *pointer到底是要对应function,还是int pointer。
回复

使用道具 举报

发表于 17-9-2008 12:24 PM | 显示全部楼层
不能够放同名的。。。
回复

使用道具 举报

发表于 17-9-2008 06:28 PM | 显示全部楼层
原帖由 geekman 于 12-8-2008 12:01 PM 发表
你不应该把variable name 设为和 function name 一样是因为 function pointer:

int some_name(int arg)
{
...//some function operations...
}
void *pointer = some_name; //pointer now point to a functio ...


function pointer 应该是这样 declare :-

int (*pointer)(int) = some_name;

[ 本帖最后由 yccheok 于 17-9-2008 06:30 PM 编辑 ]
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

 

ADVERTISEMENT



ADVERTISEMENT



ADVERTISEMENT

ADVERTISEMENT


版权所有 © 1996-2023 Cari Internet Sdn Bhd (483575-W)|IPSERVERONE 提供云主机|广告刊登|关于我们|私隐权|免控|投诉|联络|脸书|佳礼资讯网

GMT+8, 23-12-2025 12:48 PM , Processed in 0.147748 second(s), 24 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表