0
object *head = NULL, *tail = NULL;  // EDIT
struct object { 
           vector <int> data;
           object * read ( void ) ;
           struct obj {
                obj *next; 
                object * brach ( object * ) ;
           };
};

object * object :: read ( void ) {
     ... // some code to read and return  (dynamically token space) pointer
}
object * object :: obj :: brach ( object * p ) {
     ... // some code to make link list and pointer to middle 
}

void show ( object * p ) {
     ... // to show data, from head to tail
}

A lot of question about nested structure, but I think all of them have similiar answer

  • If I want to put show function in read function, how can I use global show function in it?

    some effort ;

    object * object :: read ( void ) {
    
     ... // some code to read and return  (dynamically token space) pointer
    
     :: show ( head ) ;  ( ! ) 
    
     head :: obj :: show ( head ) ; ( ! )
    
     head . obj . show ( head ) ;   ( ! )
    
     }  
    

    all of the line marked with ( ! ), gives error, WHY

  • in main function

    object *p = new object ;
    ... // some code to read data
    object *tmp = NULL;
    tmp = p -> obj . brach ( p ) ; ( ! ) 
    
    **how** can I fix it ? 
    
2
  • can you tell us what errors you are getting? And what is "head"? Commented Jan 27, 2011 at 11:06
  • @Chris Card, I did not store the errors, sorry Commented Jan 27, 2011 at 11:07

2 Answers 2

1

Need more source code. Here are not declared variables after that can guess, which name belongs o which type. But:

The show(object*) function is a global function, so the call do not needs any prefix.

The object structure has any obj type member variable. Only a structure is declared and defined some methods of own and of its structure. So in the main function it cannot call the obj::brach method only if it would be a static function.

Declare a obj* head; member in object structure, create it (p->head = new object::obj()), and then call p->head->brach(..);

Sign up to request clarification or add additional context in comments.

Comments

0

Seems you are from a non-C++ background (C#?). In response to some of your queries: Correct way to address a global from your scope of object::read() is either simply Show(Head) or ::Show(head) - I suspect the reason you are having problems here is because head is not defined.

In you main procedure you need to use the -> operator to dereference pointer specifically instead of: p.obj.brach(p) you are wanting p->obj->brach(p)

There seems to be a lot else wrong in the code and ideas expressed here but it's difficult to advise you without more source code and an idea of what you are trying to do.

2 Comments

head is defined in global, but I forget to add it
Indeed, you need to either put the definition of show above the definition of read or forward declare the function.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.