473,395 Members | 1,631 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Modular programming

bob
I have made a file: box.h that have some structs, simple functions
etc.

I have then made another file: print.h that have a class 'print' with
methods to print the content from 'box' (content of various structs,
fields etc) which currently does not work.

in box.h I write:

#include "print.h"

And then I make a new print object like 'Print p' and it works fine
when I from 'box.h' do something like:

p.printLine()

But how do I make 'print.h' aware of the types and struct in box.h?

In box.h I have the struct 'Line'. I would like to pass this struct to
a Print object like:

Line test;
p.printLine2(test);
Therefore I have in print.h written:

#include "box.h"

but when I define the function in print.h:

void printLine2(Line a) {
std::cout << "test\n";
}

I just get:

error: 'Line' has not been declared
Why can I use print.h in box.h but not make print.h aware of the types
in box.h?

Sep 26 '07 #1
1 2373
in box.h I write:
>
#include "print.h"
Therefore I have in print.h written:

#include "box.h"
There's your problem - every time the compiler reads in one .h file,
you're telling it to look in the other one. Your compiler is obviously
smart enough to realise the problem, but the side effect is that your
function definition is being read before the definition of Line.

The real issue of course is that you're putting code into the .h files.
The .h files are only meant for definitions. If you put code into .h
files you're not actually writing modular programs, as after all the
#include directives have been processed you will only have one really
big module.

What you need to do is to split the code into multiple .cpp files, as
each .cpp file is normally treated as one module, regardless of how many
..h files it includes.

There should be plenty of tutorials on the web explaining how to do this
in more detail.

Cheers,
Adam.
Sep 27 '07 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

14
by: Hayden Kirk | last post by:
Hey guys I am about to write some back end software for my business. I want a system that I can create invoices, clients etc... I can do this no problem. However I want to write it in modules so...
18
by: Zero | last post by:
Hi, I am calculating an integer to the pwer of a large integer, e.g. 2^5000. It turns out that the result I always get is zero. I am sure that the result is too large to store in such type...
4
by: Nick Goloborodko | last post by:
Hi, I'm in the process of conceptualizing a new ASP.NET application. I'm a relative newbie in ASP.NET / .NET in general, so any comments will be greatly appreciated. Basically i need to make...
12
by: Don Huan | last post by:
Hi my job is to migrate our WinForms application to ASP.NET. This app was build very modular so every peace of code can be replaced by another "modul". There are 1 VS-solution with about 60...
26
by: I_AM_DON_AND_YOU? | last post by:
This is the scenario: I have a VB.Net project comprising of a few Forms. On Form1 I have more than 20 buttons. There is a very lenghty code written in click event of each and every button. Right...
26
by: ashu | last post by:
lets look at the code given below here i m trying to do mudular programming /* this is my main prog.*/ /*mmod.c*/ #include<stdio.h> #include "mod1.h" int main(void) {
20
by: Tuvas | last post by:
I have made and recently posted a libary I made to do Modular Arithmetic and Prime numbers on my website at http://www.geocities.com/brp13/Python/index.html . I am currently in a crypotology...
3
by: DG | last post by:
Please correct me if i'm using a wrong term. I want to programm functionality and pack it to .dll Then, have an application look in 'modules' folder and depending on available .dll-s display...
2
by: Canice | last post by:
I'm working on a web application where 90% of it is common 'product' code an the other 10% is customer specific. I want some method of separating the customer specific presentation, business and...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.