簡體   English   中英

C++:將對象傳遞給函數

[英]c++: Passing objects to functions

我正在瀏覽一段代碼,在那里我遇到了一些問題,並且能夠破解這段代碼:

#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 );
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM