If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Data Access, Manipulation & Batch Languages > Delphi, C etc > Functions In Structures !?!

View Poll Results: Why is Functions within Functions not allowed in C or C++ ?
Other languages support and because func within func is messy coding like GOTO label ?? 0 0%
IMMMpossible ! 0 0%
it's possible 1 100.00%
Don't knoe 0 0%
Voters: 1. You may not vote on this poll

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 10-09-04, 15:55
QuasarZ QuasarZ is offline
Registered User
 
Join Date: Oct 2004
Posts: 1
Functions In Structures !?!

1)How do u access functions that are within structures and make them return a value to not the main but to another (void) function ? ( Dunno if qn is phrase is correctly ??)
2)Below is an excerpt from a vending machine program in C++ but how do u convert to C without using :the scope resolution operator) ? or Is the below program unable to be converted to C...
BTW: some reasoning of the program may be wrong especially the data inside Convert_to_Denom as this part is wat me coded moiself...^^;;

Mani Thks for all who readin tis


#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<ctype.h>

struct coins{


int denomination;

void setDenom(int);
int getDenom();
};

struct machine{

struct coins ten, twenty, fifty;
};

void Convert_to_Denom(struct machine *m);

main()
{
struct machine *mac;
Convert_to_Denom(&mac);

return 0;
}

void Convert_to_Denom(struct machine *m)
{
m->fifty.setDenom(50);
m->twenty.setDenom(20);
m->ten.setDenom(10);

printf("%d",m->fifty.getDenom());
printf("%d",m->twenty.getDenom());
printf("%d",m->ten.getDenom());

}
void coins::setDenom(int D)
{
denomination = D;
}

int coins::getDenom()
{
return denomination;
}
Reply With Quote
  #2 (permalink)  
Old 11-18-04, 22:03
twburger twburger is offline
Registered User
 
Join Date: Nov 2004
Posts: 8
Functions within structures and Convert C++ to C

Well as for question 1 - Huh? Do you mean in C or C++? In either you can use a pointer to a function as a parmeter of another function so the value is passed in the stack an not held in storage within the scope on the main program body.

Question 2 - You mostly have the code in C format already. All you need to do is not declare the functions inside of a class (you declared it as a structure).

You need to study. We do do not do your homework here. BTW please attempt proper grammatical syntax in you corresponence. Sloppy language promotes sloppy code.
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On