473,789 Members | 2,732 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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(te st);
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 2407
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
3778
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 its extendable in the future. Like someone else can write a module for it and it can plug stright into my system. I can't figure out a good way to do this in php. I was thinking of hooks or something, but PHP does not support this.
18
5643
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 as u_int64_t and long int etc. My power function is as follows: for(i=0; i<5000; i++) result *= 2;
4
2310
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 my application as modular as possible, something along the lines of Mambo (PHP CMS System) Drupal (another PHP CMS) or something similar to these. What I'm thinking is to provide the following structure: core of the application includes essential...
12
2216
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 projects (dll's) in it. Now I have to design a Web-Client modul (actually the web-interface). To maintain the modularity, I thought of making one ASP.NET-Project inside of the solution and create some projects containing Custom Web Controls. Did...
26
4857
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 now I haven't used any sub procedure. I mean to say I am writing the code directly in the click event. So it's become very lengthy and therefore to figure out some problem or make any changes I have to scroll at lot. Also in addition to click...
26
1680
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
6825
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 class, and am working on building a RSA public key cryptology system for a class project. I am building the librarys just to get the experience to do so. However, I would ask if any of you know of any gaping security holes that can easily be seen from...
3
6767
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 available functionalities. What is term for this kind of programming, can you provide me with MSDN topic? Thanx.
2
3482
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 data access layers from the product code as I don't the main product code to be bloated with customer specific code. Ideally I'd like to have one solution for the product and one for each customer. However I haven't found a way to separate the...
0
9666
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10410
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10200
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10139
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9020
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7529
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6769
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5551
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3701
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.