Thread: new B: classes

  1. #1
    Registered User
    Join Date
    May 2003
    Posts
    6

    new B: classes

    I am working on a trasition from JAVA to C++

    I was wondering if it would be possible to call classes which are in other files.... for example:

    FILE 01
    Code:
    class no1
    int multiply(int num)
    {
       return (num * num);
    }
    FILE 02
    Code:
    class no2
    void main()
    {
       no1.multiply(numbah);   <-- or something like that
    }
    Maybe JAVA is just too simplified and weak... *sigh*

    Any help or tips would be reeeeeally appreciated, thanx!

    (all of this happens inside the same project, mind you)
    Last edited by NetPsycho; 05-26-2003 at 04:00 AM.

  2. #2
    Veni Vidi Vice
    Join Date
    Aug 2001
    Posts
    343
    I was wondering if it would be possible to call classes which are in other files.... for example:
    Yes, just write the class-implementation in a file e.i. file1.cpp and the corresponding class-declaration in file1.h

    Then just include the correct header. Also check up the keyword extern.
    01000111011011110110111101100100 011101000110100001101001011011100110011101110011 01100100011011110110111001110100 01100011011011110110110101100101 01100101011000010111100101110011 0110100101101110 01101100011010010110011001100101
    Good things donīt come easy in life!!!

  3. #3
    Registered User
    Join Date
    May 2003
    Posts
    6
    Uhm , I have no idea of what you just wrote....

  4. #4
    Registered User codingmaster's Avatar
    Join Date
    Sep 2002
    Posts
    309
    he says, that you have to include the file, which includes your class



    #include "classfile.hpp"

    .
    .
    .
    .
    .
    .

    YOUR CODE

    .
    .
    .
    .

  5. #5
    Veni Vidi Vice
    Join Date
    Aug 2001
    Posts
    343
    E.i
    Put this in your header-file file1.h (prefix *.h is compiler dependent, se documentation for yourīs compiler)
    Code:
    //This is called the declaration for the class
    class Test
    {
    public:
    Test(int pNumber);
    int getNumber() const;
    private:
    int mnumber;
    };
    and this in file.cpp
    Code:
    //Respectivly this is called the implementation of the class
    Test::Test(int pNumber)
    {
    mnumber = pNumber;
    }
    
    int Test::getNumber() const
    {
    return mnumber;
    }
    And if you want to use this class in main()
    Code:
    #include <iostream>
    //Now you can use the class Test
    #include "file1.h"
    
    int main()
    {
    Test anobject(10);
    return 0;
    }
    01000111011011110110111101100100 011101000110100001101001011011100110011101110011 01100100011011110110111001110100 01100011011011110110110101100101 01100101011000010111100101110011 0110100101101110 01101100011010010110011001100101
    Good things donīt come easy in life!!!

  6. #6
    Registered User
    Join Date
    May 2003
    Posts
    6
    Thank you...
    I will attempt to put this newfound knowledge to good use.

    Once again, thank you!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Can you Initialize all classes once with New?
    By peacerosetx in forum C++ Programming
    Replies: 12
    Last Post: 07-02-2008, 10:47 AM
  2. Multiple Inheritance - Size of Classes?
    By Zeusbwr in forum C++ Programming
    Replies: 10
    Last Post: 11-26-2004, 09:04 AM
  3. im extreamly new help
    By rigo305 in forum C++ Programming
    Replies: 27
    Last Post: 04-23-2004, 11:22 PM
  4. Exporting VC++ classes for use with VB
    By Helix in forum Windows Programming
    Replies: 2
    Last Post: 12-29-2003, 05:38 PM
  5. include question
    By Wanted420 in forum C++ Programming
    Replies: 8
    Last Post: 10-17-2003, 03:49 AM