首页 > 类的定义和声明分别写在.h与.cpp中出现LINK2019错误

类的定义和声明分别写在.h与.cpp中出现LINK2019错误

定义的成员函数有些可以正常调用,有些出现错误:LINK2019 该符号在函数 _wmain 中被引用
.h

#pragma once
#define  MaxVertexNum 600
#include <string>
#include <vector>
using namespace std;
#include "MainNode.h"

class Graph
{
public:
    enum GraphStyle                                                // 图的类型
    {
        DG,                                                        // 有向图
        DN,                                                        // 有向网
        UDG,                                                       // 无向图
        UDN                                                        // 无向网
    };
    Graph( GraphStyle = DG);                            // 构造函数,默认图的类型为有向图
    virtual ~Graph(void);
    int LocateVertex(const string);                        // 根据string val,找到顶点在顶点表中的序号
    inline int GetNumV();                                // 取得图中的顶点数目
    inline int GetNumE();                                    // 取得图中的边数
    bool InsertVertex(const string);                       // 插入一个顶点
    bool Insertedge(const string, const string); // 插入一条边
    int GetMainval(const string);//得到点string的点权值
    int GetRowval(const string,const string);//得到边string1——string2的边权值
    int getaroundV(const string,const vector<string>);//得到点string周围点的个数和详细是哪些点
private:
    vector<MainNode> vertices;   //想用HASH 找的快点                                      // 顶点表
    int numVertices;                                            // 顶点个数
    int numedges;                                                // 边数
    int maxVertices;                                            // 最多可存放的顶点个数
    GraphStyle style;                                           // 图的类型
    //void DFS(void (*Visit)(const VertexType&), int);            // 从一个顶点出发深度优先遍历图
    //bool *visited;                                              // 在遍历时存放是否访问过的标志

};

.cpp

Graph::Graph( GraphStyle gs) : numVertices(0), numedges(0), maxVertices(MaxVertexNum), style(gs)// 构造函数.初始化,gs为图的类型,默认为有向图DG
{
}

Graph::~Graph()// 析构函数
{
    for (int i = 0; i < numVertices; i++)
        vertices[i].ClearedgeList();
    if (maxVertices != 0)
        vertices.clear();
}

int Graph::LocateVertex(const string vex)
// 根据顶点的数据,找到顶点在顶点表中的序号
// 参数vex为顶点的数据
// 返回值为顶点的序号。如返回-1,未找到相关的顶点
{
    for (int i = 0; i < numVertices; i++)
        if (vertices[i].val== vex)
            return i;
    return -1;
}

int Graph::GetNumV()//顶点数
{
    return numVertices;

}
int Graph:: GetNumE()//边数
{
    return numedges;
}

bool Graph::InsertVertex(const string vex)//false已存在,
// 在图中插入一个顶点
// 参数vex为要插入的顶点数据
{
    if (numVertices == maxVertices)//再插就多了
        return false;

    // 判断相同的顶点是否存在,如存在,则返回
    for (int i = 0; i < numVertices; i++)
        if (vertices[i].val == vex)
        {
            vertices[i].vval++;//点权值++,单独的点总是加入
            return false;
        }
    // 增加一个顶点项
    MainNode mainnode(vex);
    vertices.push_back(mainnode);
    numVertices++;

    return true;

}
主程序
#include "stdafx.h"
#include "Graph.h"
int _tmain(int argc, _TCHAR* argv[])
{
        enum Graph::GraphStyle gs;
    gs=Graph::DG;
    Graph testg(gs);
    testg.InsertVertex("a");
    testg.InsertVertex("c");
    testg.Insertedge("a","c");
    int n=testg.GetNumE();
    int m=testg.GetNumV();


    
    system("pause");
    return 0;
}

插图边和点的成员函数正常
但返回点的个数和边数的函数报错


建议把你的代码分别用三个`包起来

//你的代码

【热门文章】
【热门文章】