This Stack Overflow post describes a solution based on the subfig package, but the latter has compatibility problems with the ubiquitous hyperref package (see Stephan's post) and the subcaption package is recommended instead of subfig.
Below is my attempt at a solution using subcaption. It's not optimal---lacks automation and the vertical spacing between listing and caption is a bit off---but it should get you halfway there.

\documentclass{article}
% -----------------------------------------------
\usepackage{filecontents}
% I generate the source files here for completeness of the MWE.
% In practice, those three files should sit in some folder accessible to pdflatex.
\begin{filecontents*}{config.h}
// Choose one of the supported encoding options:
//#define STRING_ENCODING_ASCII
#define STRING_ENCODING_UCS32
//#define STRING_ENCODING_UTF8
#include "rules.h"
\end{filecontents*}
\begin{filecontents*}{rules.h}
#ifdef STRING_ENCODING_UCS32
#define ENCODING_HEADER "encoding/ucs32.h"
#endif
\end{filecontents*}
\begin{filecontents*}{text.cpp}
#include "config.h"
#include ENCODING_HEADER
\end{filecontents*}
% -----------------------------------------------
\usepackage{kantlipsum} % for filler text
\usepackage{float} % for defining a new float env. (multilisting)
\newfloat{multilisting}{tbphH}{lopbl}
\floatname{multilisting}{Listing}
\usepackage{subcaption} % for defining a custom subfloat env. (submultilisting)
\DeclareCaptionSubType{multilisting}
\captionsetup[submultilisting]
{
font = {tt,normalsize},
justification = raggedright,
singlelinecheck = off,
}
\usepackage{listings}
\lstset
{
language = C++,
numbers = left,
frame = single,
captionpos = b,
}
\usepackage{hyperref}
% new macro for a bit more automation
\newcommand\sublstinputlisting[2][1]
% 1: multiplying factor of \textwidth;
% 2: path to source file
{
\begin{submultilisting}[b]{#1\textwidth}
\lstset
{
title = \lstname,
captionpos = t,
}
\lstinputlisting{#2}%
\end{submultilisting}%
}
% macro code undefined in your incomplete example, so I just coded my own
\newcommand\code[1]{\texttt{#1}}
\begin{document}
\lstlistoflistings
\vfill
\kant[1]
\begin{multilisting}
\sublstinputlisting[0.85]{config.h}
\par
\sublstinputlisting[0.8]{rules.h}
\par
\sublstinputlisting[0.45]{text.cpp}
\captionsetup{type=lstlisting}%
\caption{The \code{\#include \emph{macropath}} pattern.}
\label{my_cplusplus_listing}
\end{multilisting}
\begin{lstlisting}[caption = test listing]
test
test
\end{lstlisting}
\end{document}