構造体の使用からクラスの使用に移行しようとしていますが、完全ではありませんが、クエリを説明するのに十分なコードについていくつか質問があります(これらを明確にしていただきありがとうございます)。
引数、特に現在残しているヘッダーファイルの行を取り込むコンストラクターの作成に問題があります
neighborAtt(int neighbor_id, int att_1, int att_2);
。構造体として使用する場合
neighborAtt
、私はそれを簡単に行うことができましたneighborAttributes currentNode(neighborID, att1, att2);
。クラス相当とは何ですか?.cppファイルでは、コンストラクターを。として定義する必要があることを知っています
neighborAtt::neighborAtt()
。関数(つまり、neighborAtt ::を含める)でこれを行う必要がありますか、それとも私が行ったことは正確ですか?
これは私のヘッダーファイルです:
#if !def connectivity_H
#define connectivity_H
#include <iostream>
#include <vector>
#include <list>
#include <string>
#include <sstream>
#include <fstream>
class listAtt;
class vecListAtt;
class neighborAtt //contains the neighbour and associated attributes of a node
{
public:
neighborAtt();
neighborAtt(int neighbor_id, int att_1, int att_2);
vecListAtt connFrFile(int file_ext);
vecListAtt makeList(std::vector<std::list<neighborAtt>> nodeAndInfo, int nodeID, neighborAtt neighAndAtt);
neighborAtt getAtt(std::string currentLine);
private:
int neighborID;
int attribute1;
int attribute2;
};
typedef std::list<neighborAtt> listAtt;
typedef std::vector<listAtt> vecListAtt;
#endif
および.cppファイル:
#include "stdafx.h"
#include "connectivity.h"
neighborAtt::neighborAtt(): neighborID(0), attribute1(0), attribute2(0) {}
//neighborAtt::neighborAtt constructor with arguments
vecListAtt connFrFile(int file_ext)
{
//code
}
neighborAtt getAtt(std::string line)
{
//code
}