我在MFC中自己创建了个graph类(无基类),里边有几个成员变量和一个生产邻接矩阵的函数。可是总提示这个错误
graph.obj : error LNK2005: "class graph G" (?G@@3Vgraph@@A) already defined in arc.obj
ksDlg.obj : error LNK2005: "class graph G" (?G@@3Vgraph@@A) already defined in arc.obj
StdAfx.obj : error LNK2005: "class graph G" (?G@@3Vgraph@@A) already defined in arc.obj
step2.obj : error LNK2005: "class graph G" (?G@@3Vgraph@@A) already defined in arc.obj
Debug/ks.exe : fatal error LNK1169: one or more multiply defined symbols found
怎么回事?

解决方案 »

  1.   

    我graph.h的内容是:// graph.h: interface for the graph class.
    //
    //////////////////////////////////////////////////////////////////////#include   <dos.h> 
    #include   <conio.h>  
    #include   <stdlib.h> 
    #include   <string.h> 
    #include   <time.h>
    #define   INFINITY   30000         //定义一个权值的最大值 
    #define   MAX_VERTEX_NUM   20      //最大节点数#if !defined(AFX_GRAPH_H__1102FAC8_E360_49DF_892E_E071E9356A90__INCLUDED_)
    #define AFX_GRAPH_H__1102FAC8_E360_49DF_892E_E071E9356A90__INCLUDED_#if _MSC_VER > 1000
    #pragma once
    #endif // _MSC_VER > 1000class graph  
    {
    public:
    graph();
    void  CreateGraph();
    virtual ~graph();
     int   arcs[MAX_VERTEX_NUM][MAX_VERTEX_NUM];   //邻接矩阵 
     int   vexnum,arcnum; //图的当前顶点和边数 
     int   start,end;
         int   weight;
    };#endif // !defined(AFX_GRAPH_H__1102FAC8_E360_49DF_892E_E071E9356A90__INCLUDED_)
      

  2.   

    graph.cpp是:// graph.cpp: implementation of the graph class.
    //
    //////////////////////////////////////////////////////////////////////#include "stdafx.h"
    #include "ks.h"
    #include "graph.h"#ifdef _DEBUG
    #undef THIS_FILE
    static char THIS_FILE[]=__FILE__;
    #define new DEBUG_NEW
    #endif//////////////////////////////////////////////////////////////////////
    // Construction/Destruction
    //////////////////////////////////////////////////////////////////////graph::graph()
    {
    for(int i=0;i <G.vexnum;i++) 
            for(int j=1;j <=G.vexnum;j++) 
                arcs[i][j]=INFINITY; 
    }
    void  graph::CreateGraph() 
    {//构造邻接矩阵结w构的图G 
    srand((int)time(0)); //设置随机数种子
        weight=11;    
    for(int n=0;n<5;n++)
    {
    int j=1+(int)(10.0*rand()/(RAND_MAX+1.0)); //产生10以内的随机数
    if(j<weight)
    weight=j;
    }
            arcs[start][end]=weight; 
    }
    graph::~graph()
    {}