Thread: Modules and Member Functions

  1. #1
    Registered User
    Join Date
    Apr 2008
    Posts
    31

    Modules and Member Functions

    I have 3 files: stack.h, calc,c and stack.c
    Code:
    void make_empty(void);
    int is_empty(void);
    int pop(void);
    Code:
    #include "stack.h"
    main() {
         make_empty();
         ...
    }
    Code:
    #include "stack.h"
    int contents[100];
    int top = 0;
    //function definitions
    I get that stack.h is the interface, calc.c is the client and that stack.c is the implementation of the module. My question is: What exactly is the module? The definition is "a collection of services", so I thought that would be stack.c, but it isn't?

    Also if you can access data members of a structure using the . and -> operator, why can't you use it with objects and member functions?
    Code:
    struct blah{
        int a;
        int b;
    };
    
    blah *abc;
    abc->a = 0;
    Since -> means (*abc).a, why can't you use it when calling member functions outside the class?
    Code:
    class Fraction {
       int denom;
       int num;
    
    public:
       void reduce();
    };
    
    Fraction *f1, *f2;
    f1->reduce();

  2. #2
    Hurry Slowly vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,788
    why can't you use it when calling member functions outside the class?
    you can
    All problems in computer science can be solved by another level of indirection,
    except for the problem of too many layers of indirection.
    – David J. Wheeler

  3. #3
    Registered User
    Join Date
    Apr 2008
    Posts
    31
    hehe, oops... must have zoned out when the prof was explaining it.
    Thanks for clearing that up!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Find Injected DLLs In A Process?
    By pobri19 in forum Windows Programming
    Replies: 35
    Last Post: 02-06-2010, 09:53 AM
  2. Replies: 28
    Last Post: 07-16-2006, 11:35 PM
  3. Help with inheritance using modules
    By Asmodan in forum C++ Programming
    Replies: 3
    Last Post: 05-14-2002, 07:42 PM