问题描述
我有两个不同的类(class1 class2),它们都有自己的头文件和cpp文件。 Class2包含class1的头。 Class1有两个公共结构。
我想从class1中调用一个方法,并传递两个指向结构的指针。
I've two different classes (class1 class2) both of them have their own header and cpp files. Class2 has included the header of class1. Class1 has two structures which are public.I want to call a method from class2 in class1 and to pass two pointers pointing on the structures.
在class1中从class2调用方法。 (obj是class1中class2的对象):
The call of the method from class2 in class1. (obj is an object of class2 in class1):
obj.routine(ip_s.c_str(), &NLP_data_recv, &recv_data_data); //write to harddrive
在class2中声明方法之后:
Following the declaration of the method in class2:
int routine(std::string raw_data_re, struct NLP_data_header_package *Header_data, struct NLP_data_data_package *Data_data);
发生以下错误:
"argument of type ""com::NLP_data_data_package *"" is incompatible with parameter of type ""NLP_data_data_package *""
我如何解决这个问题?谢谢。
How can I solve this problem? Thank you.
编辑:附加代码:
class com header(class1):
class com header(class1):
#ifndef COM_H
#define COM_H
//...
#include "Dateiverwaltung.h"
//...
class com
{
private:
Dateiverwaltung obj;
//...
public:
int run(void);
com(std::array<std::string,TWO> socket);
~com();
struct NLP_data_header_package
{
//...
}NLP_data_recv;
struct NLP_data_data_package
{
//...
}recv_data_data;
class com cpp(class1)
class com cpp (class1)
//...
if (recv_command == DATA_COMMAND)
{
obj.routine(ip_s.c_str(), &NLP_data_recv, &recv_data_data); //write to harddrive
obj.ext_close_file();
}
//...
class Dateiverwaltung header(class2)
class Dateiverwaltung header(class2)
#ifndef DATEIVERWALTUNG_H
#define DATEIVERWALTUNG_H
//...
#include "communication.h"
//...
public:
Dateiverwaltung(char* directory_global_re);
~Dateiverwaltung();
int routine(std::string raw_data_re, struct NLP_data_header_package *Header_data, struct NLP_data_data_package *Data_data);
int ext_close_file(void);
//...
class Dateiverwaltung cpp(class2)
class Dateiverwaltung cpp (class2)
//...
int Dateiverwaltung::routine(string raw_data_re, struct NLP_data_header_package *Header_data, struct NLP_data_data_package *Data_data)
{
//...
推荐答案
错误说有一个com :: NLP_data_data_package
和NLP_data_data_package
The error says there's a "com::NLP_data_data_package"and a "NLP_data_data_package"
这是两个不同的类(对于编译器),因为它们似乎被定义在不同的命名空间,即com和默认命名空间。
That's two different classes (for the compiler), since they seem to be defined in different namespaces, namely com and the default namespace.
这篇关于将一个C ++ struct指针从一个类传递给另一个类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!