0

Im kinda new to programming, so my question is a simple one. I have came across term of data structures, and have been toying with some basic exsamples of them. While

int *pointer [10];
struct cell{
  int death;
};
int main ()
{
  cell test;
  cell * pointer[0];
  pointer[0] = &test;
  pointer[0] -> death = 5;
  cout <<  pointer[0] -> death ;  
  cin.get();
  return 0;
}

Works perfectly fine, it shows an error whenever i try to get the "cout" part into a function

int *pointer [10];
struct cell{
  int death;
};  
int test() {cout <<  pointer[0] -> death;}
int main ()
{
  cell test;
  cell * pointer[0];
  pointer[0] = &test;
  pointer[0] -> death = 5;
  test()
  cin.get();
  return 0;
}

And I wonder why it happens, and how to pull it correctly.

Thank you for your help.

2
Contributors
2
Replies
3
Views
10 Years
Discussion Span
Last Post by SpiderKing
0
int *pointer [10];
struct cell{
  int death;
};  
int test() {cout <<  pointer[0] -> death;}
int main ()
{
  cell test;
  cell * pointer[0];
  pointer[0] = &test;
  pointer[0] -> death = 5;
  test()
  cin.get();
  return 0;
}

You've declared pointer twice.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.