我有指針和引用與std :: vector和std :: string的具體問題。一些問題在下面的代碼中被剪下,一些在下面。C++,指針,引用,從一個到另一個函數,std :: vector,std :: string
我有基本的代碼
//first of all: is this function declaration good?
//or shoudl I already pass the std::vector in another way?
//I'm only reading from it
void func(const std::vector<std::string>& vec)
{
//I need to call otherFunc(void*) with a single element from vec:
//otherFunc(void* arg);
//with arg being a void* to vec[0]
}
我的IDE告訴我,只有&*vec[0]
作品參數otherFunc
,但這並不編譯...
如何是最好的方式做這些一種參數傳遞?
你需要解釋你想傳遞給函數的東西。它自己的「void *」是沒有意義的。要使用「void *」,您必須首先將其轉換爲其他類型。那麼,「void *」函數的功能是什麼? – user9876
我不知道,因爲它來自外部庫。我不能改變'otherFunc(void *)',我只能改變我自己的'func()'。 – blubberbernd