简体   繁体   English

如何传递类对象作为对另一个头文件功能的引用

[英]How to pass class object as a reference to another header file's function

I have main.cpp 我有main.cpp

#include "Customer.h"
#include "Driver.h"

 int main(){
   Customer o_customer;        //Customer class object
   //ManageMenu is a Driver.h method
      ManageMenu( o_customer );   //calling method

  return 0;
}

My Driver.h is just a .h and .cpp file which does not have any class in it. 我的Driver.h只是一个.h.cpp文件,其中没有任何类。 What it does is handles all the screen display method, sample 它所做的是处理所有屏幕显示方法,示例

#include "Customer.h"
void ManageMenu( Customer & customer );

and, here is the issue , I am not able to pass the object reference in this function and I also believe that it is valid too as it simply means that we are passing the reference to some function. 而且,这就是问题所在,我无法在此函数中传递对象引用,并且我也认为它也是有效的,因为这仅意味着我们正在将引用传递给某个函数。

My Driver.cpp 我的Driver.cpp

#include "Driver.h"
void ManageMenu( Customer & customer ){
 //do something
   //calls the method of Customer's class
customer.AddDetails();

}

I am not able to pass the object, the error which I am getting in g++ is 我无法传递对象,我在g++遇到的错误是

error: variable or field 'ManageMenu' declared void
error: 'Customer' was not declared in this scope
        'customer' was not declared in this scope
 void ManageMenu( Customer & customer );

Please help me out and do explain me where I am doing the mistake. 请帮助我,并向我解释我在哪里做错了。 THANKS!! 谢谢!!

在Driver.cpp中,您忘记添加

#include "Customer.h"

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何将对 object 的引用传递给另一个 class - How to pass a reference to an object to another class 如何通过引用传递对象以供另一个文件使用 - how to pass an object by reference to be used by another file C ++头文件需要引用另一个类的功能 - C++ Header File Needs a Reference to a Function of Another Class 如何将类的对象传递给对象的类函数中的函数? - How to pass a object of a class to a function within the object's class function? 如何在C ++中的另一个类的头文件中正确包含一个类的头文件? - How to correctly include a class's header file in another class's header file in C++? 如何传递 object 或参考 function? - How to pass an object or reference to a function? 如何正确地将 class object 的引用传递给 C++ 中的另一个类对象 - How do I correctly pass a reference of a class object into another class-object in C++ 如何将矢量结构从一个头文件传递到另一个头文件中的类 - How to pass a vector struct from one header file to class in another header file 如何将模板化服务传递到类中,而不在该类头中包含该服务的头文件? - How do I pass a templated service into a class without including that service's header file in that class header? 如何将一个对象作为另一个类构造函数的参数传递? - How to pass an object as another class constructor's parameter?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM