User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the C++ section within the Software Development category of DaniWeb, a massive community of 455,993 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 3,798 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our C++ advertiser: Programming Forums
Views: 413 | Replies: 2
Reply
Join Date: Aug 2007
Posts: 2
Reputation: SpiderKing is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
SpiderKing SpiderKing is offline Offline
Newbie Poster

data structures

  #1  
Dec 6th, 2007
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.
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Mar 2005
Location: Phnom Penh, Cambodia
Posts: 415
Reputation: invisal will become famous soon enough invisal will become famous soon enough 
Rep Power: 5
Solved Threads: 36
invisal's Avatar
invisal invisal is offline Offline
Posting Pro in Training

Re: data structures

  #2  
Dec 6th, 2007
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.
Yesterday is a history, tomorrow is a mystery, today is a gift.
Behind every smile is a tear.
Visal .In
Reply With Quote  
Join Date: Aug 2007
Posts: 2
Reputation: SpiderKing is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
SpiderKing SpiderKing is offline Offline
Newbie Poster

Re: data structures

  #3  
Dec 6th, 2007
Thank you for your answer, think it works now.
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

DaniWeb C++ Marketplace
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes

Similar Threads
Other Threads in the C++ Forum

All times are GMT -4. The time now is 9:38 am.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC