OOD plz help: from c#/java to c++

This is a discussion on OOD plz help: from c#/java to c++ within the C++ Programming forums, part of the General Programming Boards category; I have a brief 2 part question: I am a recent graduate of a newer Information tech program. During the ...

  1. #1
    Registered User itignition's Avatar
    Join Date
    Jun 2008
    Location
    Vancouver, B.C.
    Posts
    3

    Question OOD plz help: from c#/java to c++

    I have a brief 2 part question:

    I am a recent graduate of a newer Information tech program.
    During the course of my 3 year curriculum we used Java/c#/PHP/JS (as you can see,
    the highest level programming languages) for developing our solutions.

    I have been porting to c++ to have better access to kernel and system level
    operations and hardware accessibility.

    Part 1 of my question is:

    Can I structure my solutions in c++ using the same methodology as I do in
    Java/C# (with classes) performing object related functions and reduce coupling of my code.


    I have noticed that c++ uses classes and or structs. Many web examples and
    book examples of the usage of classes declare them before the int main(void) function.

    So is it wrong to have a structure using header files like class
    files .cs (c#) files or .java(JAVA) files.


    Example:

    player.h
    team.h
    board.h

    main.cpp
    gameEngine.cpp

    view.cpp (GUI)

    I hope someone can address this question. Thank you!

  2. #2
    Registered User
    Join Date
    Apr 2008
    Posts
    890
    Quote Originally Posted by itignition View Post
    Can I structure my solutions in c++ using the same methodology as I do in
    Java/C# (with classes) performing object related functions and reduce coupling of my code.
    Sure, but keep in mind you don't "import" other classes and modules - you include their definitions via header files. Your C++ text should cover this.

    So is it wrong to have a structure using header files like class
    files .cs (c#) files or .java(JAVA) files.
    I don't understand this question.

  3. #3
    Registered User itignition's Avatar
    Join Date
    Jun 2008
    Location
    Vancouver, B.C.
    Posts
    3
    Quote Originally Posted by medievalelks View Post
    Sure, but keep in mind you don't "import" other classes and modules - you include their definitions via header files. Your C++ text should cover this.


    So is it wrong to have a structure using header files like class
    files .cs (c#) files or .java(JAVA) files.


    I don't understand this question.
    Thank you for your prompt reply.

    I knew that this sentence might get confusing. I'm just trying to get a mental picture of what the equivalent of a java.class or .cs file. is in c++ (.h or .cpp).

    Thanks again..

    P.S. It is a bit confusing as a learner going from the high level code to assembly (C#-> JAVA -> C++ -> C -> Fortran -> assembly ) rather than the traditional C/C++ -> JAVA -> C#

  4. #4
    BMJ
    BMJ is offline
    Banal internet user BMJ's Avatar
    Join Date
    Aug 2002
    Location
    Chicagoland
    Posts
    1,380
    Quote Originally Posted by itignition View Post
    So is it wrong to have a structure using header files like class
    files .cs (c#) files or .java(JAVA) files.


    Example:

    player.h
    team.h
    board.h

    main.cpp
    gameEngine.cpp

    view.cpp (GUI)
    No it's not wrong at all.

    Generally you would structure your files such that a class called CPlayer would be defined in a file like CPlayer.h, implemented in CPlayer.cpp, and may be called somewhere else like in main.cpp. The compiler would compile CPlayer.cpp and main.cpp into object code, and the linker will perform code relocation and link the object code files together to create the final executable.

  5. #5
    Registered User
    Join Date
    Dec 2006
    Location
    Canada
    Posts
    3,183
    .class = .o (object files, more or less, but you can't run a .o file without linking)
    .java = .cpp

    a header (.h) is like an interface in java

  6. #6
    Registered User
    Join Date
    Apr 2006
    Posts
    2,032
    Typically classes are devided into two parts: a header file, with a *.h or *.hpp extension and a source file with a *.cpp or *.C extension.

    The header file contains the class definition. This lists the members and methods in the class. It also contains the declarations (prototypes) of any free functions (functions not belonging to any class). There are other things that can go in header files, but its not worth listing them off.

    Then the source contains the function and method definitions (methods are functions that arn't free), and the initialization of static variables.

    Header files are then included in sources files that need to access them, much like importing in java.

    There are also special cases where the stuff that normally goes in source files belongs in headers. This happens with inline functions and templates.
    It is too clear and so it is hard to see.
    A dunce once searched for fire with a lighted lantern.
    Had he known what fire was,
    He could have cooked his rice much sooner.

  7. #7
    Registered User itignition's Avatar
    Join Date
    Jun 2008
    Location
    Vancouver, B.C.
    Posts
    3

    Smile

    King Mir, cyberfish, BMJ, medievalelks

    Thank you all for great input. You have helped me gain clarity for my question.

    All the best!

  8. #8
    Registered User
    Join Date
    Apr 2008
    Posts
    890
    Quote Originally Posted by cyberfish View Post
    a header (.h) is like an interface in java
    A pure virtual class is like an interface in Java. There is no real equivalent to the .h in Java.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. can any1 plz make this assignment
    By jean in forum C Programming
    Replies: 17
    Last Post: 05-13-2009, 09:19 PM
  2. [Request] Need Help Plz
    By TylerD in forum Tech Board
    Replies: 4
    Last Post: 01-03-2009, 08:54 AM
  3. Socket class OOD
    By lord mazdak in forum C++ Programming
    Replies: 6
    Last Post: 12-17-2005, 12:11 AM
  4. Anyone plz help me
    By Rose_Flowers in forum A Brief History of Cprogramming.com
    Replies: 1
    Last Post: 09-17-2003, 12:01 PM
  5. help plz plz
    By nsssn73 in forum C++ Programming
    Replies: 2
    Last Post: 06-03-2002, 08:44 AM

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