Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
2.0k views
in Technique[技术] by (71.8m points)

convert reference to pointer representation in C++

Is there a way to "convert" a reference to pointer in c++? In example below, func2 has already defined prototype and I can't change it, but func is my API, and I'd like to either pass both parameters, or one (and second set to NULL) or neither (both set to NULL):

void func2(some1 *p1, some2 *p2);

func(some1& obj, some2& obj2)
{
   func2(..);
}
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

func2(&obj, &obj2);

Use reference parameters like normal variables.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...