c++:将对象传递给函数

c++: Passing objects to functions

本文关键字:函数 对象 c++      更新时间:2023-10-16

我正在经历一段代码,在那里我遇到了一些问题,并且能够破解这段代码:

#include <iostream>
#include <stdint.h>
#include <unistd.h>
#include <errno.h>
#include <vector>
#include <sys/types.h>
using namespace std;
class abc {
  public:
    abc(int x,int y) {
      cout << "x:" << x << endl;
      cout << "y:" << y << endl;
    }
    virtual ~abc() {}
    enum example {
      a = 1,
      b = 2,
      c = 3,
      d = 4
    };
};
template<typename T>
class xyz {
  public:
    void some_func(abc *a) {
      cout<<"some_func called"<<endl;
    }
};
int main() {}

我想调用函数

some_func()

main().我应该怎么做。有人可以帮助我吗?

您需要创建一个模板类 xyz 的某种专用化对象和一个 abc 类型的对象。

例如

int main()
{
   abc a( 10, 20 );
   xyz<int> x;
   x.some_func( &a );
}