0
我想創建一個具有在運行時確定大小的數組的類。但是,當我嘗試訪問「addToSet」函數中的數組時,我收到「未聲明的標識符錯誤」。任何幫助,將不勝感激。我是C++新手。錯誤與動態數組
頭文件:
class ShortestPathSet
{
private:
//Variables
int *pathSet;
public:
//Variables
int size;
//Constructor
ShortestPathSet(int numVertices);
//Functions
void addToSet(int vertice, int distance);
};
類文件:
#include "ShortestPathSet.h"
using namespace std;
ShortestPathSet::ShortestPathSet(int numVertices)
{
size = numVertices;
pathSet = new int[numVertices];
}
void addToSet(int vertice, int distance)
{
pathSet[vertice] = distance;
}
因此,即使使用「命名空間標準」我仍然必須包括這個?另外,非常感謝你! –
@KarlTaht這與'namespace std'無關。爲了在類定義之外定義一個類成員函數,你需要用類名來限定它。 – Barry
那麼我應該不使用頭文件來簡化這個類嗎? –