开发者

C++ how to initialize? [closed]

开发者 https://www.devze.com 2023-03-13 11:53 出处:网络
It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical andcannot be reasonably answered in its current form. For help clari
It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help cent开发者_高级运维er. Closed 11 years ago.

add: I tried on the fun below anyone know what is the error?

struct node {

  string info;
  node *link;
  node() {
    info = "string";
    link = NULL;

  }

};

void fun( node &node) {

     if (node.link !=NULL) {  
      fun (node.link);
    }

}

I get an error message when I use it inside of my functions:

invalid initialization of reference of type ‘node&’ from expression of type ‘node*’

What is the proper way to initialize it?


You're trying to pass a pointer instead of an actual object reference. Simply dereference the pointer like this:

void fun( node &node) {

     if (node.link !=NULL) {  
      fun ( *(node.link) );
    }
0

精彩评论

暂无评论...
验证码 换一张
取 消