Modules and Member Functions

This is a discussion on Modules and Member Functions within the C++ Programming forums, part of the General Programming Boards category; 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() { ...

  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
    CSharpener vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,473
    why can't you use it when calling member functions outside the class?
    you can
    The first 90% of a project takes 90% of the time,
    the last 10% takes the other 90% of the time.

  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, 08: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

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21