私はC++を学んでいて、クラスの使用に非常に慣れており、クラスを使用しようとすると非常に混乱します。既存のコード(構造体を使用)を変換してクラスを使用しようとしています。そのため、何をしようとしているのかはわかっていますが、正しく実行しているかどうかはわかりません。
クラスの関数を使用するときは、最初にクラスのオブジェクトをインスタンス化する必要があると言われました。したがって、メイン関数で試したのは(スニペット)、次のとおりです。
int main()// line 1
{
string message_fr_client = "test"; //line2
msgInfo message_processed; //line 3
message_processed.incMsgClass(message_fr_client); //line 4
if (!message_processed.priority_check(qos_levels, message_processed)) //line 5
cout << "failure: priority level out of bounds\n"; //line 6
return 0; //line 7
}
次の仮定が正しいかどうかを明確にするのを手伝ってもらえますか?コンパイラはエラーを表示していないので、エラーがないのか、その下にエラーが潜んでいるのかはわかりません。
- 4行目で、関数
incMsgClass
は文字列に対して実行されmessage_fr_client
、結果(および変更された)を返していmessage_processed
ますか? - 5行目で、関数
priority_check
はで実行されてmessage_processed
おり、ブール値を返していますか? - 私のクラス定義には、-
getPath
の値を変更することを目的とした関数があります。nodePath
それは単に使用するだけの問題message_processed.getPath(/*arguments*/)
ですか?
関数が機能することがわかっているので、関数の本体は含めませんでした。クラス関数がどのように相互作用するかを知りたいだけです。もっと明確にできるかどうか教えてください-ここで混乱を解消しようとしています。
これが私のクラスです:
#ifndef clientMsgHandling_H
#define clientMsgHandling_H
#include <list>
#include <map>
#include <queue>
class msgInfo
{
public:
msgInfo();
msgInfo(int, int, int, std::string, std::list<int>);
/*classifying message*/
msgInfo incMsgClass(std::string original_msg);
/*message error checks*/
bool priority_check(int syst_priority, msgInfo msg); //check that message is within qos levels
bool route_check(std::map<std::pair<int, int>, int> route_table, msgInfo msg); //check that route exists
void getPath(msgInfo msg, std::map<std::pair<int, int>, int> route_info, int max_hop);
private:
int source_id;
int dest_id;
int priority;
std::string payload;
std::list<int> nodePath;
};
#endif