| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 2544 人关注过本帖
标题:请教关于error LNK2005的问题
取消只看楼主 加入收藏
thunderxu
Rank: 1
等 级:新手上路
帖 子:15
专家分:0
注 册:2006-4-27
收藏
 问题点数:0 回复次数:6 
请教关于error LNK2005的问题
编程时遇到一个关于error LNK2005的问题,不知道那位高手能帮我解决!不胜感激!

我定义了两个类,geo和coe。两个类的成员数据和成员函数的申明分别写在两个文件里,"geometrical.h","coeffcient.h"和"geometrical.cpp"和"coeffcient.cpp"。
同时,class coe: private geo
{
……………………
}

在每个".cpp"文件的开头都#include 对应的".h",如下所示(coe.cpp有所不同)
//geometrical.cpp
#include "geometrical.h"
………………
………………

//coeffcient.cpp
#include "geometrical.cpp"
#include "coeffcient.h"
………………
………………

最后在main()里:
#include "coefficient.cpp"
编译通过了,但在link时发生了如下的错误:
geometrical.obj : error LNK2005: "public: __thiscall geo::geo(double,double,double,int,int,int)" (??0geo@@QAE@NNNHHH@Z) already defined in coefficient.obj
geometrical.obj : error LNK2005: "protected: void __thiscall geo::fndimension(void)" (?fndimension@geo@@IAEXXZ) already defined in coefficient.obj
main.obj : error LNK2005: "public: __thiscall geo::geo(double,double,double,int,int,int)" (??0geo@@QAE@NNNHHH@Z) already defined in coefficient.obj
main.obj : error LNK2005: "protected: void __thiscall geo::fndimension(void)" (?fndimension@geo@@IAEXXZ) already defined in coefficient.obj
main.obj : error LNK2005: "public: __thiscall coe::coe(double,double,double,int,int,int)" (??0coe@@QAE@NNNHHH@Z) already defined in coefficient.obj
main.obj : error LNK2005: "public: void __thiscall coe::fncoedefine(void)" (?fncoedefine@coe@@QAEXXZ) already defined in coefficient.obj
main.obj : error LNK2005: "public: void __thiscall coe::fncoefficientF(double * * *,double * * *,double * * *,double,double)" (?fncoefficientF@coe@@QAEXPAPAPAN00NN@Z) already defined in coefficient.obj
main.obj : error LNK2005: "public: void __thiscall coe::fnDUVW(void)" (?fnDUVW@coe@@QAEXXZ) already defined in coefficient.obj
main.obj : error LNK2005: "public: void __thiscall coe::fncoefficientP(double)" (?fncoefficientP@coe@@QAEXN@Z) already defined in coefficient.obj
main.obj : error LNK2005: "public: void __thiscall coe::fnpseudoV(double * * *,double * * *)" (?fnpseudoV@coe@@QAEXPAPAPAN0@Z) already defined in coefficient.obj
LIBCD.lib(wincrt0.obj) : error LNK2001: unresolved external symbol _WinMain@16
Debug/test1.exe : fatal error LNK1120: 1 unresolved externals

每个头文件里都写了语句#pragma once,但仍然出现这种错误。

我又在每个头文件里写了
#ifndef ***.h
#define ***.h

………………

#endif
但还是不行。

小弟为VC++菜鸟,还往那位高手不惜赐教!万分感谢!
搜索更多相关主题的帖子: cpp error geometrical coeffcient 
2006-05-02 14:45
thunderxu
Rank: 1
等 级:新手上路
帖 子:15
专家分:0
注 册:2006-4-27
收藏
得分:0 

多谢!

2006-05-03 08:52
thunderxu
Rank: 1
等 级:新手上路
帖 子:15
专家分:0
注 册:2006-4-27
收藏
得分:0 
但是如果不#include "*.cpp"文件,怎么才能由一个main文件调用其他的cpp文件呢?因为其他的cpp文件都是写在不同的文件中的呀!
2006-05-03 09:10
thunderxu
Rank: 1
等 级:新手上路
帖 子:15
专家分:0
注 册:2006-4-27
收藏
得分:0 
不行,用.h做扩展名还是不行
是不是因为我有一个类的继承呀!
2006-05-04 22:32
thunderxu
Rank: 1
等 级:新手上路
帖 子:15
专家分:0
注 册:2006-4-27
收藏
得分:0 
这是我的全部代码。可能有点长!

/******************************************************/
/******************************************************/
#include "geometrical.cpp"
#include "coefficient.h"
#include <cmath>
void coe::fncoedefine()
{
int i,j,k;
…………
}

2006-05-04 23:15
thunderxu
Rank: 1
等 级:新手上路
帖 子:15
专家分:0
注 册:2006-4-27
收藏
得分:0 
void coe::fncoefficientF(double ***FXI,double ***FYI,double ***FZI,double coeRO,double coeDif) //coefficients for variables, such as u,v,T, etc.
{
……………………
……………………
……………………
}
void coe::fnDUVW()
{
int i,j,k;
…………………………
}
//**********************************************************
void coe::fncoefficientP(double RO) //calculate the coefficients for pressure
{
…………………………
}
/*****************************************************/
/*****************************************************/
void coe::fnpseudoV(double ***F,double ***coeSOURCE)
{
……………………
}



#include <iostream.h>
#include "geometrical.h"

void geo::fndimension()
{

……………………
}



//coefficient.h
#pragma once
class coe:private geo
{
………………
};

//geometrical.h
#pragma once
class geo
{
……………………
};


//#include "geometrical.h"
//#include "geometrical.h"
//#include "coefficient.h"
#include "coefficient.h"
#include <iostream.h>
int main()
{
……………………
……………………
return 0;
}

//*****************************************************************
void fndefine()
{

…………
}
//******************************************************************

代码太长,我只能把主要的列出来!
还希望哪位高手能帮我解决这个问题!
2006-05-04 23:15
thunderxu
Rank: 1
等 级:新手上路
帖 子:15
专家分:0
注 册:2006-4-27
收藏
得分:0 
但是如果那样的话会占用大量的计算机内存呀!会影响计算速度!
2006-05-05 08:42
快速回复:请教关于error LNK2005的问题
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.012605 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved