473,729 Members | 2,309 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

class templates with pointers to each other in seperate header files

Ben
I'm kind of new to creating templates. I've made some small class and
function templates in the past and I have used quite of bit of the STL,
but I am having problems tyring to create templates.

I'm trying to make class templates in seperate header files with
pointers to each other, and I am getting strange errors.

Is it possible to do?

May 27 '06
12 2091
Alf P. Steinbach wrote:
It may be that we're not really disagreeing.

However, what you wrote has as its limit to not include other headers in
a header, and leave that to the implementation files, since what you
"absolutely /have to/" include is zero, nix, nada; a common practice
with Microsoft (e.g. Visual Studio generated headers are that way).
I see now whence came confusion. I could have stated it less strongly,
but do note that I gave several examples of what I meant by "absolutely
have to" -- base classes, by-value members, and typedefs. The
Microsoft Way you describe evidently jumps through hoops to elide even
these, with the consequences you describe. So, I'll try to be less
liberal with universal qualifiers, but I do wonder whether you really
thought I meant to recommend such an extreme, given that doing so would
contraindicate the examples I explicitly gave.
Since I only criticized that abhorrent practice, not stating anything
about my own preferences, perhaps that would be in order; see ch 1.6 of
<url: http://home.no.net/dubjai/win32cpptut/html/w32cpptut_01.ht ml>,
I'll have to satisfy myself with the section you quoted -- downloading
and unzipping a word doc is generally past my pain threshold for casual
newsreading. HTML-ify it and I'll gladly take a peek.
where the most important quote is (quoting myself :-) )
I get accused of that a lot when I cite Scott Meyers. ;)
"A header file
should always be self-contained: it should be possible to just #include
it without having to #include any other headers first"; subject to that
requirement it's fine to minimize the dependencies, otherwise IMO not.


Yes. This strikes me as so fundamental that I would rather state it as
an absolute than suggest any ambiguity.

Luke

May 28 '06 #11
Ben
> Certainly.

It's unfortunate that so many people are taught to add #includes into
headers for everything their class uses. You should only #include what
you absolutely *have to* in a header (most commonly base classes,
by-value members (when not using pimpl), and typedefs), and leave the
rest for the implementation file. This really helps to cut down on
build times and recompilation.

While you're looking at the FAQ, take a peek at the section on posting
etiquette and quoting conventions -- really helps if you indicate what
you're replying to.


Aaahh...I finally figured it out! I just removed the #include <B.h>
from A.h, and put an #include <B.h> in front of everywhere that there
is an #include <A.h>

May 28 '06 #12

Luke Meyers wrote:
Alf P. Steinbach wrote:
It may be that we're not really disagreeing.

However, what you wrote has as its limit to not include other headers in
a header, and leave that to the implementation files, since what you
"absolutely /have to/" include is zero, nix, nada; a common practice
with Microsoft (e.g. Visual Studio generated headers are that way).


I see now whence came confusion. I could have stated it less strongly,
but do note that I gave several examples of what I meant by "absolutely
have to" -- base classes, by-value members, and typedefs. The
Microsoft Way you describe evidently jumps through hoops to elide even
these, with the consequences you describe. So, I'll try to be less
liberal with universal qualifiers, but I do wonder whether you really
thought I meant to recommend such an extreme, given that doing so would
contraindicate the examples I explicitly gave.
Since I only criticized that abhorrent practice, not stating anything
about my own preferences, perhaps that would be in order; see ch 1.6 of
<url: http://home.no.net/dubjai/win32cpptut/html/w32cpptut_01.ht ml>,


I'll have to satisfy myself with the section you quoted -- downloading
and unzipping a word doc is generally past my pain threshold for casual
newsreading. HTML-ify it and I'll gladly take a peek.
where the most important quote is (quoting myself :-) )


I get accused of that a lot when I cite Scott Meyers. ;)
"A header file
should always be self-contained: it should be possible to just #include
it without having to #include any other headers first"; subject to that
requirement it's fine to minimize the dependencies, otherwise IMO not.


Yes. This strikes me as so fundamental that I would rather state it as
an absolute than suggest any ambiguity.

Luke


M$ headers suck a lot!
Try using winsock2.h and you will see wonders

even openGL headers may annoy the M$ unexperienced user :-(

May 29 '06 #13

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

Similar topics

1
2568
by: Vince C. | last post by:
Hi all, I've created XML documents that are described with a schema. I'm using those documents to create web pages. All my web pages contain a fixed header and a variable document part. The header is the same in each page and is described in an XML document, "Head.xml". The document part, which is variable in content, is described in other XML files (e.g. "Document.xml", "Product.xml", "Register.xml").
15
2777
by: Mon | last post by:
I am in the process of reorganizing my code and came across and I came across a problem, as described in the subject line of this posting. I have many classes that have instances of other classes as member variables. So including a forward declaration doesnt help, does it? Faced with these, I had the following options: -Include the appropriate header in the header file that contains the class definition that has a member variable that is...
7
2859
by: Srini | last post by:
Hello, Rules for inline functions say that they have to be defined in the same compilation unit as their declarations. For class member functions this means that the inline member functions must be defined either within the class or within the same header file. But its generally a good programming practice to have the declarations and definitions in seperate files. This would make the future maintenance of the code easier.
7
12965
by: A_StClaire_ | last post by:
hi, I'm working on a project spanning five .cpp files. each file was used to define a class. the first has my Main and an #include for each of the other files. problem is my third file needs to access the class defined in my second file and I can't figure out how to work this right. if I use an #include in my third file, my Main gives me a compile-time class redefinition error. if I don't, the third file can't "see" the second
14
4430
by: Murkland | last post by:
Hi. I have a problem with a template class that I'm trying to inherit from. The code for the base class is: template <class T> class BaseClass { public: BaseClass(); ~BaseClass();
7
3462
by: mathieu | last post by:
Hello, I did read the FAQ on template(*), since I could not find an answer to my current issue I am posting here. I have tried to summarize my issue in the following code (**). Basically I am trying to hide the `complexity` of template from the user interface. If you look at the code DataSet should be the object that my user manipulate. Unfortunately by doing so the object returned by DataSet::Get is a FloatingPt, so without the virtual...
4
7999
by: zfareed | last post by:
#include <iostream> #include <fstream> using namespace std; template<class ItemType> class SortedList { private:
15
7864
by: akomiakov | last post by:
Is there a technical reason why one can't initialize a cost static non- integral data member in a class?
6
391
by: Gaijinco | last post by:
I'm trying to do a template class Node. My node.hpp is: #ifndef _NODE_HPP_ #define _NODE_HPP_ namespace com { namespace mnya { namespace carlos { template <typename T>
0
8917
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
9426
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
9281
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
9200
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
9142
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8148
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
6722
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
6022
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();...
1
3238
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.