首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > C++ >

快急疯了,求大家解决一个VC++编译有关问题,一天了也不知道为什么

2012-03-20 
快急疯了,求大家解决一个VC++编译问题,一天了也不知道为什么好像是在c.h中定义的一些宏不起作用,为什么错

快急疯了,求大家解决一个VC++编译问题,一天了也不知道为什么
好像是在c.h中定义的一些宏不起作用,为什么
错误提示:
Compiling...
aaa.cpp
ALGO2-1.CPP
BO2-1.CPP
d:\11\sfdf\bo2-1.cpp(3)   :   error   C2146:   syntax   error   :   missing   '; '   before   identifier   'InitList '
d:\11\sfdf\bo2-1.cpp(3)   :   error   C2501:   'Status '   :   missing   storage-class   or   type   specifiers
d:\11\sfdf\bo2-1.cpp(3)   :   fatal   error   C1004:   unexpected   end   of   file   found
StdAfx.cpp
Error   executing   cl.exe.
ggg.exe   -   3   error(s),   0   warning(s)

//BO2-1.CPP的代码:
#include   "stdafx.h "
  Status   InitList(SqList   &L)   //   算法2.3   /////指示此行出错
  {   //   操作结果:构造一个空的顺序线性表
      L.elem=(ElemType*)malloc(LIST_INIT_SIZE*sizeof(ElemType));
      if(!L.elem)
          exit(OVERFLOW);   //   存储分配失败
      L.length=0;   //   空表长度为0
      L.listsize=LIST_INIT_SIZE;   //   初始存储容量
      return   OK;
  }


//ALGO2-1.CPP主程序代码:
#include "c1.h "   在后
  typedef   int   ElemType;
  #include "c2-1.h "   //   采用线性表的动态分配顺序存储结构
  #include "bo2-1.cpp "   //   可以使用bo2-1.cpp中的基本操作

  Status   equal(ElemType   c1,ElemType   c2)
  {   //   判断是否相等的函数,Union()用到
      if(c1==c2)
          return   TRUE;
      else
          return   FALSE;
  }

  void   Union(SqList   &La,SqList   Lb)   //   算法2.1
  {   //   将所有在线性表Lb中但不在La中的数据元素插入到La中
      ElemType   e;
      int   La_len,Lb_len;
      int   i;
      La_len=ListLength(La);   //   求线性表的长度
      Lb_len=ListLength(Lb);
      for(i=1;i <=Lb_len;i++)
      {
          GetElem(Lb,i,e);   //   取Lb中第i个数据元素赋给e
          if(!LocateElem(La,e,equal))   //   La中不存在和e相同的元素,则插入之
              ListInsert(La,++La_len,e);
      }
  }

  void   print(ElemType   &c)
  {
      printf( "%d   ",c);
  }

  void   main()
  {
      SqList   La,Lb;
      Status   i;
      int   j;
      i=InitList(La);
      if(i==1)   //   创建空表La成功
          for(j=1;j <=5;j++)   //   在表La中插入5个元素
              i=ListInsert(La,j,j);
      printf( "La=   ");   //   输出表La的内容
      ListTraverse(La,print);
      InitList(Lb);   //   也可不判断是否创建成功
      for(j=1;j <=5;j++)   //   在表Lb中插入5个元素
          i=ListInsert(Lb,j,2*j);
      printf( "Lb=   ");   //   输出表Lb的内容


      ListTraverse(Lb,print);
      Union(La,Lb);
      printf( "new   La=   ");   //   输出新表La的内容
      ListTraverse(La,print);
  }


//头文件c.h
  //   c1.h   (程序名)
  #include <string.h>
  #include <ctype.h>
  #include <malloc.h>   //   malloc()等
  #include <limits.h>   //   INT_MAX等
  #include <stdio.h>   //   EOF(=^Z或F6),NULL
  #include <stdlib.h>   //   atoi()
  #include <io.h>   //   eof()
  #include <math.h>   //   floor(),ceil(),abs()
  #include <process.h>   //   exit()
  #include <iostream.h>   //   cout,cin
  //   函数结果状态代码
  #define   TRUE   1
  #define   FALSE   0
  #define   OK   1
  #define   ERROR   0
  #define   INFEASIBLE   -1
  //   #define   OVERFLOW   -2   因为在math.h中已定义OVERFLOW的值为3,故去掉此行
  typedef   int   ElemType;  
  typedef   int   Status;   //   Status是函数的类型,其值是函数结果状态代码,如OK等
  typedef   int   Boolean;   //   Boolean是布尔类型,其值是TRUE或FALSE


//   c2-1.h   线性表的动态分配顺序存储结构
  #include "c1.h "

#define   LIST_INIT_SIZE   10   //   线性表存储空间的初始分配量
  #define   LISTINCREMENT   2   //   线性表存储空间的分配增量
  struct   SqList
  {
      ElemType   *elem;   //   存储空间基址
      int   length;   //   当前长度
      int   listsize;   //   当前分配的存储容量(以sizeof(ElemType)为单位)
  };


把#include   "c1.h "   #include   "c2-1.h "加入到bo2-1.cpp中会出现以下错误:
--------------------Configuration:   ggg   -   Win32   Debug--------------------
Compiling...
BO2-1.CPP
Skipping...   (no   relevant   changes   detected)
aaa.cpp
ALGO2-1.CPP
Linking...
ALGO2-1.OBJ   :   error   LNK2005:   "int   __cdecl   InitList(struct   SqList   &) "   (?InitList@@YAHAAUSqList@@@Z)   already   defined   in   aaa.obj
ALGO2-1.OBJ   :   error   LNK2005:   "int   __cdecl   DestroyList(struct   SqList   &) "   (?DestroyList@@YAHAAUSqList@@@Z)   already   defined   in   aaa.obj
ALGO2-1.OBJ   :   error   LNK2005:   "int   __cdecl   ClearList(struct   SqList   &) "   (?ClearList@@YAHAAUSqList@@@Z)   already   defined   in   aaa.obj
ALGO2-1.OBJ   :   error   LNK2005:   "int   __cdecl   ListEmpty(struct   SqList) "   (?ListEmpty@@YAHUSqList@@@Z)   already   defined   in   aaa.obj
ALGO2-1.OBJ   :   error   LNK2005:   "int   __cdecl   ListLength(struct   SqList) "   (?ListLength@@YAHUSqList@@@Z)   already   defined   in   aaa.obj
ALGO2-1.OBJ   :   error   LNK2005:   "int   __cdecl   GetElem(struct   SqList,int,int   &) "   (?GetElem@@YAHUSqList@@HAAH@Z)   already   defined   in   aaa.obj
ALGO2-1.OBJ   :   error   LNK2005:   "int   __cdecl   LocateElem(struct   SqList,int,int   (__cdecl*)(int,int)) "   (?LocateElem@@YAHUSqList@@HP6AHHH@Z@Z)   already   defined   in   aaa.obj


ALGO2-1.OBJ   :   error   LNK2005:   "int   __cdecl   PriorElem(struct   SqList,int,int   &) "   (?PriorElem@@YAHUSqList@@HAAH@Z)   already   defined   in   aaa.obj
ALGO2-1.OBJ   :   error   LNK2005:   "int   __cdecl   NextElem(struct   SqList,int,int   &) "   (?NextElem@@YAHUSqList@@HAAH@Z)   already   defined   in   aaa.obj
ALGO2-1.OBJ   :   error   LNK2005:   "int   __cdecl   ListInsert(struct   SqList   &,int,int) "   (?ListInsert@@YAHAAUSqList@@HH@Z)   already   defined   in   aaa.obj
ALGO2-1.OBJ   :   error   LNK2005:   "int   __cdecl   ListDelete(struct   SqList   &,int,int   &) "   (?ListDelete@@YAHAAUSqList@@HAAH@Z)   already   defined   in   aaa.obj
ALGO2-1.OBJ   :   error   LNK2005:   "int   __cdecl   ListTraverse(struct   SqList,void   (__cdecl*)(int   &)) "   (?ListTraverse@@YAHUSqList@@P6AXAAH@Z@Z)   already   defined   in   aaa.obj
ALGO2-1.OBJ   :   error   LNK2005:   "int   __cdecl   equal(int,int) "   (?equal@@YAHHH@Z)   already   defined   in   aaa.obj
ALGO2-1.OBJ   :   error   LNK2005:   "void   __cdecl   Union(struct   SqList   &,struct   SqList) "   (?Union@@YAXAAUSqList@@U1@@Z)   already   defined   in   aaa.obj
ALGO2-1.OBJ   :   error   LNK2005:   "void   __cdecl   print(int   &) "   (?print@@YAXAAH@Z)   already   defined   in   aaa.obj
ALGO2-1.OBJ   :   error   LNK2005:   _main   already   defined   in   aaa.obj
BO2-1.OBJ   :   error   LNK2005:   "int   __cdecl   InitList(struct   SqList   &) "   (?InitList@@YAHAAUSqList@@@Z)   already   defined   in   aaa.obj
BO2-1.OBJ   :   error   LNK2005:   "int   __cdecl   DestroyList(struct   SqList   &) "   (?DestroyList@@YAHAAUSqList@@@Z)   already   defined   in   aaa.obj
BO2-1.OBJ   :   error   LNK2005:   "int   __cdecl   ClearList(struct   SqList   &) "   (?ClearList@@YAHAAUSqList@@@Z)   already   defined   in   aaa.obj
BO2-1.OBJ   :   error   LNK2005:   "int   __cdecl   ListEmpty(struct   SqList) "   (?ListEmpty@@YAHUSqList@@@Z)   already   defined   in   aaa.obj
BO2-1.OBJ   :   error   LNK2005:   "int   __cdecl   ListLength(struct   SqList) "   (?ListLength@@YAHUSqList@@@Z)   already   defined   in   aaa.obj
BO2-1.OBJ   :   error   LNK2005:   "int   __cdecl   GetElem(struct   SqList,int,int   &) "   (?GetElem@@YAHUSqList@@HAAH@Z)   already   defined   in   aaa.obj
BO2-1.OBJ   :   error   LNK2005:   "int   __cdecl   LocateElem(struct   SqList,int,int   (__cdecl*)(int,int)) "   (?LocateElem@@YAHUSqList@@HP6AHHH@Z@Z)   already   defined   in   aaa.obj
BO2-1.OBJ   :   error   LNK2005:   "int   __cdecl   PriorElem(struct   SqList,int,int   &) "   (?PriorElem@@YAHUSqList@@HAAH@Z)   already   defined   in   aaa.obj
BO2-1.OBJ   :   error   LNK2005:   "int   __cdecl   NextElem(struct   SqList,int,int   &) "   (?NextElem@@YAHUSqList@@HAAH@Z)   already   defined   in   aaa.obj


BO2-1.OBJ   :   error   LNK2005:   "int   __cdecl   ListInsert(struct   SqList   &,int,int) "   (?ListInsert@@YAHAAUSqList@@HH@Z)   already   defined   in   aaa.obj
BO2-1.OBJ   :   error   LNK2005:   "int   __cdecl   ListDelete(struct   SqList   &,int,int   &) "   (?ListDelete@@YAHAAUSqList@@HAAH@Z)   already   defined   in   aaa.obj
BO2-1.OBJ   :   error   LNK2005:   "int   __cdecl   ListTraverse(struct   SqList,void   (__cdecl*)(int   &)) "   (?ListTraverse@@YAHUSqList@@P6AXAAH@Z@Z)   already   defined   in   aaa.obj
Debug/ggg.exe   :   fatal   error   LNK1169:   one   or   more   multiply   defined   symbols   found
Error   executing   link.exe.

ggg.exe   -   29   error(s),   0   warning(s)




[解决办法]
aaa 的代码呢?

[解决办法]
//BO2-1.CPP的代码:

中要include status等的申明

[解决办法]
怎得一个乱字。~~~
“把#include "c1.h " #include "c2-1.h "加入到bo2-1.cpp中会出现以下错误:”
应该是头文件重复包含,重复编译了。

可以这样解决
#ifndef _PUBLIC_H_
#define _PUBLIC_H_


public.h 中的数据定义


#endif

热点排行