这段代码在C++里怎么编译不过?

Laone 2003-08-02 11:20:16
function.h里
int isleap(int);

function.cpp里
int isleap{int y){
if (y%4==0&&y%100!=0||y%400==0)
return 1;
return 0;
}

错误提示
Error E2356 function.cpp 119: Type mismatch in redeclaration of 'isleap(int)'
Error E2344 function.h 18: Earlier declaration of 'isleap(int)'
Error E2449 function.cpp 119: Size of 'isleap(int)' is unknown or zero
Error E2141 function.cpp 119: Declaration syntax error
...全文
24 20 打赏 收藏 转发到动态 举报
写回复
用AI写文章
20 条回复
切换为时间正序
请发表友善的回复…
发表回复
Laone 2003-08-02
  • 打赏
  • 举报
回复
真是太脸红了啊,这段代码是用别人的,自己没修改,直接copy,没想到有这样的错误啊
Laone 2003-08-02
  • 打赏
  • 举报
回复
可以了啊,果然是个字符错误了
bluei 2003-08-02
  • 打赏
  • 举报
回复
老兄,容易嘛我?!
bluei 2003-08-02
  • 打赏
  • 举报
回复
faint!!!看:
int isleap{int y){
if (y%4==0&&y%100!=0||y%400==0)
return 1;
return 0;
}

头一行代码“{int y){”

guolisen 2003-08-02
  • 打赏
  • 举报
回复
把函数声明加extern试试
例如在function.h:
extern int isleap(int);
bluei 2003-08-02
  • 打赏
  • 举报
回复
真没面子。
不在乎知识产权的话,把整个工程打个包给我,baihaifei@163.com
Laone 2003-08-02
  • 打赏
  • 举报
回复
现在我什么都不include,就这样一段代码:
#include <iostream>
#include <stdio.h>

using namespace std;

int isleap(int);

int isleap{int y){
if (y%4==0&&y%100!=0||y%400==0)
return 1;
return 0;
}

int main(){
cout<<isleap(1980)<endl;
return 0;
}

Borland C++ 5.5.1 for Win32 Copyright (c) 1993, 2000 Borland
test.cpp:
Error E2356 test.cpp 8: Type mismatch in redeclaration of 'isleap(int)'
Error E2344 test.cpp 6: Earlier declaration of 'isleap(int)'
Error E2449 test.cpp 8: Size of 'isleap(int)' is unknown or zero
Error E2141 test.cpp 8: Declaration syntax error
*** 4 errors in Compile ***
bluei 2003-08-02
  • 打赏
  • 举报
回复
不行,就粘个错误信息过来;
行,就该结帖给分了。呵呵
Laone 2003-08-02
  • 打赏
  • 举报
回复
去掉#include "function.cpp",整个程序就编译不了,名称我换了很多次,还是不行
bluei 2003-08-02
  • 打赏
  • 举报
回复
首先:funciton.h里的#include "funciton.cpp"是肯定要去掉的。
接着:可能int isleap(int)在其他的文件中定义过,改个更特殊的名字试试。
三两行代码,还整不了你了,小样儿!
Laone 2003-08-02
  • 打赏
  • 举报
回复
不行啊,我在function.h里的其他函数怎么可以编译呢,就这个不能
里面还有void left(char *, int);
funciton.cpp里也有
void left(char *str, int length){
length = length>(int)strlen(str)?(int)strlen(str):length;
str[length] = '\0';
}
bluei 2003-08-02
  • 打赏
  • 举报
回复
关键就是这里,include滥用,出现声明重复!!!
去掉funciton.h里的#include "funciton.cpp"
Laone 2003-08-02
  • 打赏
  • 举报
回复
是同一目录啊
funciton.h里还加入了
#include "funciton.cpp"
liangyongwen 2003-08-02
  • 打赏
  • 举报
回复
怎么不行呢?那是因为你没有为function.h指定路径,例如function.h跟你的cpp文件放在同一目录之下,可以用#include "function.h",否则你要再""里面指定路径!编译绝对通过,不过连接不上,因为没有main()!回去试试!
Laone 2003-08-02
  • 打赏
  • 举报
回复
主文件:
#include <iostream.h>
#include <stdio.h>
#include <stdlib.h>
#include <windows.h>
#include <sql.h>
#include <sqlext.h>
#include <string.h>
#include <time.h>
#include <conio.h>
#pragma comment (lib,"odbc32.lib")
#include "env.h"
HENV henv = SQL_NULL_HENV;
HDBC hdbc = SQL_NULL_HDBC;
RETCODE retcode;
#include "odbc.h"
#include "function.h"

int main(){
return 0;
}
Laone 2003-08-02
  • 打赏
  • 举报
回复
bcc 5.5
yjh1982 2003-08-02
  • 打赏
  • 举报
回复
不可能,你用什么编译器?
bluei 2003-08-02
  • 打赏
  • 举报
回复
include用的不对了吧?好像才导致声明的问题。
把#include也粘过来看看
Laone 2003-08-02
  • 打赏
  • 举报
回复
有的啊,不#include,如何能有编译错误啊
villager 2003-08-02
  • 打赏
  • 举报
回复
main在哪里?有没有
#include<function.h>
#include<stdio.h>

64,647

社区成员

发帖
与我相关
我的任务
社区描述
C++ 语言相关问题讨论,技术干货分享,前沿动态等
c++ 技术论坛(原bbs)
社区管理员
  • C++ 语言社区
  • encoderlee
  • paschen
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
  1. 请不要发布与C++技术无关的贴子
  2. 请不要发布与技术无关的招聘、广告的帖子
  3. 请尽可能的描述清楚你的问题,如果涉及到代码请尽可能的格式化一下

试试用AI创作助手写篇文章吧