473,602 Members | 2,811 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Split a class across two source files

Hi, I have a class that is fairly large and I would like to split the
file into two files, but still use only one class. What is the best way
to accomplish this?

Thanks!

Dec 7 '05 #1
2 3136
je************@ gmail.com wrote:
Hi, I have a class that is fairly large and I would like to split the
file into two files, but still use only one class. What is the best way
to accomplish this?

Thanks!


A "fairly large" class may indicate that the class should be
redesigned, breaking it into smaller classes. However, you can declare
the class in a header file (say, MyClass.hpp) and then put the
implementation in two source files that both include the header (say,
MyClass1.cpp and MyClass2.cpp):

// In MyClass.hpp
class MyClass
{
void Foo();
void Bar();
};

// In MyClass1.cpp
#include "MyClass.hp p"
void MyClass::Foo()
{ /*...*/ }

// In MyClass2.cpp
#include "MyClass.hp p"
void MyClass::Bar()
{ /*...*/ }

Cheers! --M

Dec 7 '05 #2
Thanks... I feel silly for asking now, it was so simple. I had been
doing the same thing, only I had been including the second cpp file
from the first. Don't know what possessed me to try that, but it was
throwing the compiler for a loop.

Dec 15 '05 #3

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

Similar topics

5
31167
by: Stu Cazzo | last post by:
I have the following: String myStringArray; String myString = "98 99 100"; I want to split up myString and put it into myStringArray. If I use this: myStringArray = myString.split(" "); it will split myString up using the delimiter of 1 space so that
6
1462
by: Sridhar R | last post by:
I am looking for a class browser that has these features. 1. Given a symbol (class, method or function) it should giveback the lineno n source code 2. It should be efficient and quick. I looked at the `pyclbr` module, but it's slower. I will be _often_ regenerating the symbols from exactly one python source file. But for an average python script in my machine it takes 2 secs for pyclbr to build the dictionary of symbols.
11
2490
by: Carlos Ribeiro | last post by:
Hi all, While writing a small program to help other poster at c.l.py, I found a small inconsistency between the handling of keyword parameters of string.split() and the split() method of strings. I wonder if someone else had ever stumbled on it before, and if it has a good reason to work like it is. Both implementations take two parameters: the separator character and the max number of splits (maxsplit). However, string.split() accept
2
2444
by: Sean Dettrick | last post by:
I am wondering if it is possible to increment an integer at compile time using template<int N> (or by any other method, e.g. compiler directives etc), across multiple source files. This may sound crazy, but I wish to build a string array (which requires no user maintenance) of source file RCS version numbers! The idea is, I would like to be print the beggers out or operate on them at run time if I feel like it, by using a (maintenance...
3
1579
by: Matthias Kaeppler | last post by:
Hello, this more a question about good practice than it is about the C++ language itself, but still... my question is this: I have a class representing the main window of my application which is really growing big. Well, most of the action is happening in the main window in my app so that's okay I guess. To solve the clutter, I thought about splitting up the class into several smaller ones, but that didn't feel right, mainly because...
3
8559
by: Krish | last post by:
I have requirement, that i get one big chunk of text file. This text file will have has information, that on finding "****End of Information****", i have to split them individual text file with our naming standard (unique id) and create them designated folder. This requirement should be created as a batch job and preferrably this job should monitor the folder where one big chunk of text file lands and process them immediately. ...
2
2152
by: Martin Arvidsson, Visual Systems AB | last post by:
Hi! I have a string containing this information: Including file: Myfile.fle (C:\Program Files\Application\Source\Myfile.fle) After myfile.fle there are three spaces! Since i use the folowing:
5
5201
by: D_a_n_i_e_l | last post by:
Is it possible to split a class definition over two files? Thanks.
7
4376
by: John Smith | last post by:
Hi, I am very new to C# and NET framework. I am trying to hash (using MD5CryptoServiceProvider) a source that is split into several files. Now when the source is in one file I can produce the correct md5 hash. My issue is how can I reproduce the correct hash when the file is split into different files.
0
7993
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
7920
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
8401
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...
1
8054
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
8268
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
6730
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...
0
5440
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
3900
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...
1
2418
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.