473,790 Members | 3,265 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How Can I link a .cp file in the "main" header?

I have a .h (header file) linked using #include<...>. I also have a .cp
file which i don't know how to include in the header of my "main" file.
I have the following c++ file.
The file names are: 1) dArray.h
2) dArray.cp
3) dArrayTest.cpp

dArray.h file declares and defines a class called DynamicArray.
dArray.cp defines the functions declared as member functions in
DynamicArray class in dArray.h. This dArray.h is includded in the
header of aArray.cp with #include<...> precompiler directive.

Question is: How do I include dArray.cp in the main program called
dArrayTest.cpp? Do I use the same pre-compiler directive? And do all
the 3 files need to be in the same folder for the calling file to "see"
the included file?

Any help on this is appreciated.

Jofio

Apr 10 '06 #1
6 2475

Jofio wrote:
I have a .h (header file) linked using #include<...>. I also have a .cp
file which i don't know how to include in the header of my "main" file.
I have the following c++ file.
Put a
#include "dArray.cp"
at top of your dArrayTest.cpp file.
The file names are: 1) dArray.h
2) dArray.cp
3) dArrayTest.cpp

dArray.h file declares and defines a class called DynamicArray.
dArray.cp defines the functions declared as member functions in
DynamicArray class in dArray.h. This dArray.h is includded in the
header of aArray.cp with #include<...> precompiler directive.

Question is: How do I include dArray.cp in the main program called
dArrayTest.cpp? Do I use the same pre-compiler directive? And do all
the 3 files need to be in the same folder for the calling file to "see"
the included file?
Not necessary for all the files to be in the same folder. If I have
dArray.h in folder x,
I just have to do a #include "x/dArray.h" in dArray.cp.

Any help on this is appreciated.

Jofio


Apr 10 '06 #2
Jofio wrote:
I have a .h (header file) linked using #include<...>. I also have a .cp
file which i don't know how to include in the header of my "main" file.
I have the following c++ file.
The file names are: 1) dArray.h
2) dArray.cp
3) dArrayTest.cpp

dArray.h file declares and defines a class called DynamicArray.
dArray.cp defines the functions declared as member functions in
DynamicArray class in dArray.h. This dArray.h is includded in the
header of aArray.cp with #include<...> precompiler directive.

Question is: How do I include dArray.cp in the main program called
dArrayTest.cpp? Do I use the same pre-compiler directive? And do all
the 3 files need to be in the same folder for the calling file to "see"
the included file?


Almost all C++ implementations use two phases. In the first phase,
the compiler compiles every translation unit. A translation unit is
a source file plus all its #include's. Typically, that's one .cpp file,
some standard headers like <algorithm> and your own .h headers.
I.e. .h files are *included*.

In the second phase, the translated unites are *linked* together,
and the tool is of course called a linker. Basically this glues the
..cpp files from phase 1 together.

In your case, the dArray.cpp file should be linked to dArrayTest.cpp
by the linker, not by an include. Unlike #include, the mechanism for
that is left to the implementation. Usually there's some kind of
makefile or project file.

HTH,
Michiel Salters

Apr 10 '06 #3
I have just done what you advised. I recompiled and it gave me an error
message :

'Unable to open include file 'dArray.h'
'Unable to open include file'dArray.cp'

The result is that the compiller doesn't see the variables declared in
the 'main' program - dArrayTest.cpp - and used as an instance of the
class declared and defined in the dArray.h and dArray.cp file.

I don't seem to see any errors though ...

Here is my code in dArray.h ...
////////////////////////////////////////////////////////////////////////////////
#ifndef _MYDYNAM_
#define _MYDYNAM_

class DynamicArray{
public:
DynamicArray(in t size=10, int inc=5); //default parameters

int Length(void) const; //length of the array
int Position(void *item) const; //returns the index of an
array as a position of the item whose value is pointed to by *item
void *Nth(int n) const; //will return a an address of the
nth value in the array

void Append(void *item); //adds a value pointed to by
*item

void *Remove(void *item);
void *Remove(int itempos);

private:
void Grow(int amount); //resizes the array dynamically

int fNum; //
int fSize; //the size of array
int fCSize;
int fInc; // size of increment
void **fItem; //
};

#endif
//////////////////////////////////////////////////////////////////////////////////

Here is the part of the code in the header section of dArray.cp ...

#include<stdlib .h>
#include<iostre am.h>
#include<assert .h>
#include "dArray.h"
and here is the part of the code in the header section of my main
prog...

#include <iostream.h>
#include<string .h>
#include<stdlib .h>
#include "dArray.h" /* should this go as I have already included it
in the header of dArray.cp file */
#include "dArray.cp"

I don't think I made an error there as far as the linking/inclusions of
the .h and .cp files are concerned. however, I keep getting the error
messages I stated above.

Any help please?
Jofio

Apr 11 '06 #4
Jofio wrote:
I have just done what you advised. I recompiled and it gave me an error
message :

'Unable to open include file 'dArray.h'
'Unable to open include file'dArray.cp'

The result is that the compiller doesn't see the variables declared in
the 'main' program - dArrayTest.cpp - and used as an instance of the
class declared and defined in the dArray.h and dArray.cp file.

Have you told it where to look?

This usually takes the form of -I<path to your include files>

--
Ian Collins.
Apr 11 '06 #5
Thanks Ian.

All the files are in the same folder and so my assumption is that the
compiller will look into the current folder.

jofio

PS. The same problem is restated as a new topic so if you see it,
please ignore it.

Apr 11 '06 #6
"Jofio" wrote:
All the files are in the same folder and so my assumption is that the
compiller will look into the current folder.


A previous post suggests you are using the form '#include <header.h>'
instead of '#include "header.h"'
Many compilers will use separate include paths for each. The former
should be used for header files supplied with the compiler and/or
located in standard (for your system, that is,) directories.
The later for your own / project specific files.
If this doesn't help, you should specify to your compiler that the
current directory should be searched for include files.
For gcc, the syntax is '-I.'
Apr 11 '06 #7

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

Similar topics

0
3012
by: Phillip Montgomery | last post by:
Hello all; I'm trying to debug an issue with a java script called, SelectSockets. It appears to be a fairly common one found on the web. I downloaded the SGI Java v1.4.1 installation from SGI's webpage and installed it using SGI's swmgr application. The installation was very straight forward and there were no errors when I installed the package. Then I ran /usr/java2/bin/javac SelectSockets.java to make the SelectSockets.class file.
7
2768
by: news | last post by:
I am pretty new to Java and I just install the JDK1.4.2 03 I am getting an error when I run the class file TestChart.class with the java.exe: Exception in thread "main" java.lang.NoClassDefFoundError: I have several class files in the directory d:\personal\java-ChartGen Chart.class ChartColourScheme.class
2
45750
by: dave | last post by:
(Forgive all caps... they are there to differentiate btw question and code) THIS IS THE ERROR I KEEP GETTING. IT COMPILES BUT WHEN IT RUNS, THE FOLLOWING POPS UP: Exception in thread "main" java.lang.NoClassDefFoundError: PlayClip THIS IS MY CODE: import java.applet.*; import java.io.*; import java.net.*;
4
1952
by: Don | last post by:
Is there some way to redirect the "main" frame to another URL from within the "header" frame? Thanks, Don ----== Posted via Newsfeeds.Com - Unlimited-Uncensored-Secure Usenet News==---- http://www.newsfeeds.com The #1 Newsgroup Service in the World! 120,000+ Newsgroups ----= East and West-Coast Server Farms - Total Privacy via Encryption =----
1
1314
by: Siv Hansen | last post by:
I have a function query(String $query) in my DbConnector-class- goes like this: function query($query) { $mysqlQuery = mysql_query($query, $this->link); if(!$mysqlQuery){ $this->setError("Queryfeil: ".mysql_error()); return false; } return $mysqlQuery; }
7
4004
by: David Elliott | last post by:
I have created an application that will dynamically load other DLLs (plugins). The new plugin is a winform with an embedded IE Browser. I am wanting to have the form to run in its own thread. This would allow for other plugins and the main application to be free to do other work. I have written a little TestDriver for the plugin and am having some difficulty. If I don't use threads everything works just fine. If I do use threads, upon...
25
1917
by: mdh | last post by:
Hi all, Going quite methodically through K& R ( as some of you can attest to!), I have never seen a big diffference in declaring a function within "main" or "ahead" of it. Now, (p119, K&R II), the discussion states that "functions "whatever" " should be declared ahead of main. Is there a good reason for this? thanks.
12
7134
nomad
by: nomad | last post by:
Hi everyone; My Class has ended and I was not able to solve this problem in time, and I would still like to solve it. I got these error code. Exception in thread "main" java.lang.NullPointerException at ticketSales.TicketSales.makeEvent(TicketSales.java:185) at ticketSales.TicketInput.main(TicketInput.java:56) Anyway I have several Class This one is called TransAction
2
3961
by: lilyumestar | last post by:
This project is due by Tuesday and I haven't even gotten half of it done. Can anyone please help me with this Exception error? I've been trying to figure it out for several hours Error Message "Main" Java.lang NullPointerException at Project1.sortingByZipCode<Project1.java:80> at Project1.main<Project1.java:31> Here is the Source Code
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
9512
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10419
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
10201
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...
0
9023
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
7531
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
5424
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5552
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
2910
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.