Thread: Structures and Functions

  1. #1
    Registered User
    Join Date
    Apr 2014
    Posts
    14

    Structures and Functions

    I have been trying to find out the answner to a question I was given but no one I have talked to knows the answner. So hopefully some one on the post might know. The question is:

    In C++ there is a way we can create Structures and Functions so that we may be able to have access to those structures and Functions in more than one file. The way to do this is by creating what?

    I think it is Class templates but I was told it was wrong. If anyone can help me I would appreciate it.

    Thanks,
    R.

  2. #2
    Registered User
    Join Date
    Jun 2005
    Posts
    6,815
    Look up "header file".
    Right 98% of the time, and don't care about the other 3%.

    If I seem grumpy or unhelpful in reply to you, or tell you you need to demonstrate more effort before you can expect help, it is likely you deserve it. Suck it up, Buttercup, and read this, this, and this before posting again.

  3. #3
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    I presume you mean something along the lines of:

    Code:
    A.hpp:
    struct A { /* stuff here */ };
    void A_foo();
    extern A g_A;
    
    B.hpp:
    struct B { /* stuff here */ };
    void B_foo();
    extern B g_B;
    
    A.cpp:
    #include "A.hpp"
    A g_A;
    
    B.cpp:
    #include "B.hpp"
    B g_B;
    
    C.cpp:
    #include "A.hpp"
    #include "B.hpp"
    A a;
    A_foo();
    g_A.something = something;
    
    D:.cpp:
    #include "A.hpp"
    #include "B.hpp"
    B b;
    B_foo();
    g_B.something = something;
    And if so, the answer is yes, but you may be thinking of something else?
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  4. #4
    Registered User
    Join Date
    Apr 2014
    Posts
    14
    Thanks everyone for your information. I will look up header file.

    Thanks,
    R.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. help with structures and functions
    By DanJRA in forum C Programming
    Replies: 4
    Last Post: 09-25-2013, 05:31 AM
  2. Structures and Functions
    By Mr.Lnx in forum C Programming
    Replies: 11
    Last Post: 05-24-2013, 02:22 AM
  3. help me with structures using functions
    By magnetpest2k7 in forum C Programming
    Replies: 2
    Last Post: 10-07-2009, 01:32 AM
  4. functions and structures
    By subflood in forum C Programming
    Replies: 2
    Last Post: 06-11-2005, 06:15 PM
  5. Structures and Functions
    By Extol in forum C++ Programming
    Replies: 4
    Last Post: 05-12-2003, 07:28 PM