Thread: Need help with class

  1. #1
    Registered User
    Join Date
    Jun 2011
    Posts
    51

    Need help with class

    I have a question about classes.

    here is my situation. I have 2 classes in 2 separate header files.
    Code:
    class a {
    
    function
    int x(int);
    void y();
    };
    function void z();
    
    class b {
    
    function r;
    };
    function s;
    class a in a.h file. All class a functions are in a.cpp file
    I have
    int a::x(g)
    class b c;

    Inside this function, I want to call r,s,y and z.

    The question is How can I call these 4 functions.

  2. #2
    template<typename T> threahdead's Avatar
    Join Date
    Sep 2002
    Posts
    214
    Please have a look at how to define functions in C++:
    Code:
    <return type> <function-name>(<arguments>);
    If the functions you implemented are not static, you first need to create an object of that class before you can call any functions.

    Code:
    A *objectOfA = new A();
    objectOfA->x(10);
    // ...
    // delete object afterwards
    delete objectOfA;
    Last edited by threahdead; 06-27-2011 at 05:59 AM.

  3. #3
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    Why do you need to call new?
    This should suffice:
    Code:
    A ObjectOfA;
    ObjectOfA.x(10);
    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.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 5
    Last Post: 04-17-2008, 02:31 AM
  2. Replies: 7
    Last Post: 05-26-2005, 10:48 AM
  3. Replies: 2
    Last Post: 04-06-2005, 07:25 AM
  4. Template <class T1, class T2, class T3> error LNK2019
    By JonAntoine in forum C++ Programming
    Replies: 9
    Last Post: 10-11-2004, 12:25 PM
  5. Replies: 1
    Last Post: 12-11-2002, 10:31 PM