Trying to Pass a pointer as a parameter

So i've been stuck on this code trying to get a pointer to pass as parameter of void print_contents ( "parameter" ) but I have had the worst of luck.

I think it has to be declared as tax_ptr but im not sure as I've tried everything and nothing seems to work. Any help is much appreciated.

I keep getting variable or field 'print_contents' is declared void!

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70

#include <cstdlib>
#include <iostream>

struct tax_node
{
      char form;   // tax form letter
      int version; // tax form number
      tax_node *next;  // pointer to next node
      void print_contents (tax_ptr*& point);
};
      
typedef tax_node* tax_ptr;

using namespace std;

void print_contents (tax_ptr*& point)
{
     
     tax_ptr printer;
             
     
        cout << printer -> form;
        cout << printer -> version;
        cout << " ";
  
     
}


int main(int argc, char *argv[])
{
    tax_ptr ptr1, ptr2, ptr3, mover;
    
   
   
   
    ptr3 = new tax_node;
    ptr3 -> form = 'e';
    ptr3 -> version = 17;
   
    ptr2 = new tax_node;
    ptr2 -> form = 'd';
    ptr2 -> version = 6;
   
    ptr1 = new tax_node;
    ptr1 -> form = 'w';
    ptr1 -> version = 2;
    
    print_contents(ptr2);
    
    
    
    //for (mover=  !=NULL; mover = mover -> next)
    //    cout << ptr1 -> form << endl;

    
  

    cout << ptr3 -> form << ptr3 -> version;
    cout << ptr2 -> form << ptr2 -> version;
    cout << ptr1 -> form << ptr1 -> version;

   

    cout << "\n\n";
    system("PAUSE");
    return EXIT_SUCCESS;
}
Last edited on
(tax_ptr*& point)
This is wrong. Pointer notation seems to confuse people, but all you need is:

(tax_ptr* point)
The asterisk states that this is a pointer to a tax_ptr object.

Didn't see the typedef, you just need to write:

(tax_ptr point)

since you already have tax_ptr defined as tax_node*
In the following snip:
1
2
3
4
5
6
7
8
9
struct tax_node
{
      char form;   // tax form letter
      int version; // tax form number
      tax_node *next;  // pointer to next node
      void print_contents (tax_ptr*& point);
};
      
typedef tax_node* tax_ptr;

Look at the bolded text:

WHAT is tax_ptr at that part of the code?
It does NOT know.
Change it to tax_node*.
I highly suggest you avoid typedef'ing to pointers.
Last edited on
Topic archived. No new replies allowed.