[英]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.