我正在学习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行中,对字符串
message_fr_client
正在执行的功能和incMsgClass
返回所得到的(改性)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
对不起,我不能接受多个答案,但谢谢大家! - 所有位和bobs帮助 – sccs 2013-03-27 07:25:33