2013-03-09 243 views
0

我敢肯定,这已被问到之前,但搜索“C++”“指针”“功能”“数组”让我无处可去。C++基本双指针传递

我在主宣布一些东西,看起来像这样:

struct point{ 
    float x; 
    float y; 
    int m; 
    float points[10]; 
    point *next; 
}; 
struct neighbor{ 
    float dist; 
    point *pt; 
}; 
neighbor **candidate = NULL; 

而且我想通过“候选人”的功能,这样我可以做的:

candidate = new neighbor*[10]; 
for(int i = 0;i<10;i++) 
    candidate[i] = new neighbor; 

注满水!各种数据,然后退出函数,而不使用return语句(这很重要,因为我使用的boost线程不能使用void以外的函数),并让主函数能够看到函数所做的更改。

对不起,这是如此基本,但我认为是正确的是不工作,我似乎无法找到我在找什么。 由于提前

回答

2

接受一个参考:

void fun(neighbor **& candidate); 

或指针:

void fun(neighbor *** candidate); 

有几乎为零的理由以往任何时候都需要用C双指针间接++。你几乎肯定没有充分利用语言。