[Webinar] Streamline your web hosting managementRegister Today

x
?
Solved

C++ and the packages

Posted on 2000-01-20
8
Medium Priority
?
242 Views
Last Modified: 2010-04-10
Hey,

In general, the C++ files are organized as follow :

/include
/src

with many many files in the same directories, and sometimes some additional others directories

In Java, we use the package principle, and the source are often better organized.

I want to try to organize the C++ file like the Java file, i.e. using the package principle.
I don't know if it is a good idea, and if it is a good think for C++.
We need to change the oll C++ developers reflex (It is difficult), but I hope that it is a
good think.

Some peoples have said that they prefer to organize like the C++ way, because when
we have many many file, they will gain some time in the compilation. I'm not sure that
it is a good argument.

Does someone have comment about this ?

And the question is :

is it better to arrange the file like the old C way
or the new Java way for C++ projects ... ?

Demez Christophe

Products Manager
DigitalWave
0
Comment
Question by:cdemez
8 Comments
 
LVL 2

Expert Comment

by:dhymes
ID: 2370180
Well let us face the facts Java and C++ are two different monsters even if they are syntactically almost the same. The organization of your C++ files can be arranged anyway you want them providing you customize your makefile to organize them as such.

One way to do this would be to put all of your common source files under a common directory. Create a makefile for each directory. Then to build the whole package or library or ..... create a master makefile that will go out to each directory and do a make.

Regards,
Dave
0
 
LVL 22

Expert Comment

by:nietod
ID: 2370208
Is there a question here?
0
 
LVL 2

Expert Comment

by:dhymes
ID: 2370236
I believe the question is, how do you arrange your C++ source code in the same manner as you would a Java Package. I hope that is what was asked!!??
0
Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

 

Author Comment

by:cdemez
ID: 2370332
Edited text of question.
0
 
LVL 22

Expert Comment

by:nietod
ID: 2370412
cdemez, please don't edit the question once it has been commented on.  it makes it hard for other experts to follow the "dialog".

I don't know enough about java and these packages to be of any help, but If you are just talking about what directory in which to put source code files, that is really up too you, just doing it as you see fit. If you are talking about where in the source code file to place a #include, again that is up to you.  If there is more to it than that...
0
 
LVL 2

Expert Comment

by:dhymes
ID: 2370413
For a C++ project, in my opinion (many opinions out there), it is better to put all of the files for a particulare project within the same directory.

For instance. If you create a project called tools and you would like tools to be available anywhere, then you could create a tools library. Now, anyone that wants to use objects from your tools library should only need to include your tools header file and link in the library. So, I would create a directory called tools and put all of my tools source code in that directory.

Now, maybe I have a NetworkDevice class that I would also like to make public to the world, so I would simply create a NetworkDevice directory and include all of my class files within this directory.

Some people like to include a subdirectory for all of the header files to keep the source files seperate from the header files. In Java you don't need to worry about this. So, it is up to you, for your header files *.h you can put them in the same directory or create a seperate directory to keep them all bundled together.

Hope this helps,
Dave
0
 
LVL 2

Expert Comment

by:dhymes
ID: 2370426
Ya, this is not the same in JAVA. If you want to create a package in java you have to name the directory  MyDir and in each java source file include the "package MyDir" directive to tell the Java virtual compiler what package the source file belongs to. There are no simulare constructs in C++ since everything get compiled and linked together.

Mmm, can't think of anything else.
0
 
LVL 1

Accepted Solution

by:
ramshakal earned 200 total points
ID: 2372257
If you want to achieve same functionality as package then first know that

(1)To make classes easier to find and use, to avoid naming conflicts, and to control access, programmers bundle  groups of related classes into packages
(2) A package is a collection of related classes and interfaces that provides access protection and namespace management.

All the above people told you about how to orgainze your files in directories. But package is different than that. Look into the term NAMING CONFLICTS, CONTROL ACCESS and NAMESPACE management.
       The analogous construction to the package mechanism in C++ is the namespace (NAMESPACE) feature. Think of the package and import keyword in Java as the analogous of the namespace and using directive in C++.
0

Featured Post

Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

What is C++ STL?: STL stands for Standard Template Library and is a part of standard C++ libraries. It contains many useful data structures (containers) and algorithms, which can spare you a lot of the time. Today we will look at the STL Vector. …
C++ Properties One feature missing from standard C++ that you will find in many other Object Oriented Programming languages is something called a Property (http://www.experts-exchange.com/Programming/Languages/CPP/A_3912-Object-Properties-in-C.ht…
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.
Suggested Courses

591 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question