473,790 Members | 2,437 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

allocator: No such file or directory

Hi,

I'm following the example in "C++ Templates: The Complete Guide",
section 5.4 Template Template Parameters.

It's basics/stack8.hpp example has a statement of "#include <allocator>",
but I got an error for it.

$ cat -n allocator.cc
1 #include <allocator>
2
3 template< typename ALLOC = std::allocator< ELEM2
4 class c {};
5
6 template <typename T,
7 template <typename ELEM,
8 typename ALLOC = std::allocator< ELEM
9 class CONT = std::deque>
10 class Stack {
11 }
12
13 int main()
14 {
15 }

$ g++ -g allocator.cc -o allocator
allocator.cc:1: 23: error: allocator: No such file or directory
[...]

How to fix the above allocator.cc so that it compiles fine?

Thanks.

FYI, why template template:

5.4 Template Template Parameters

It can be useful to allow a template parameter itself to be a class
template. Again, our stack class template can be used as an example. To
use a different internal container for stacks, the application programmer
has to specify the element type twice. Thus, to specify the type of the
internal container, you have to pass the type of the container and the
type of its elements again:

Stack<int,std:: vector<int vStack; // integer stack that uses a vector

Using template template parameters allows you to declare the Stack class
template by specifying the type of the container without respecifying the
type of its elements:

stack<int,std:: vectorvStack; // integer stack that uses a vector

To do this you must specify the second template parameter as a template
template parameter...
Aug 12 '08 #1
2 2479
On Tue, 12 Aug 2008 16:07:20 -0500, * Tong * wrote:
Hi,

I'm following the example in "C++ Templates: The Complete Guide",
section 5.4 Template Template Parameters.

It's basics/stack8.hpp example has a statement of "#include <allocator>",
but I got an error for it.

$ cat -n allocator.cc
1 #include <allocator>
2
3 template< typename ALLOC = std::allocator< ELEM2
4 class c {};
5
6 template <typename T,
7 template <typename ELEM,
8 typename ALLOC = std::allocator< ELEM
9 class CONT = std::deque>
10 class Stack {
11 }
12
13 int main()
14 {
15 }

$ g++ -g allocator.cc -o allocator
allocator.cc:1: 23: error: allocator: No such file or directory
[...]

How to fix the above allocator.cc so that it compiles fine?

Thanks.
My g++:

$ g++ --version
g++ (GCC) 4.2.3 (Debian 4.2.3-1)
FYI, why template template:

5.4 Template Template Parameters

It can be useful to allow a template parameter itself to be a class
template. Again, our stack class template can be used as an example. To
use a different internal container for stacks, the application programmer
has to specify the element type twice. Thus, to specify the type of the
internal container, you have to pass the type of the container and the
type of its elements again:

Stack<int,std:: vector<int vStack; // integer stack that uses a vector

Using template template parameters allows you to declare the Stack class
template by specifying the type of the container without respecifying the
type of its elements:

stack<int,std:: vectorvStack; // integer stack that uses a vector

To do this you must specify the second template parameter as a template
template parameter...
Aug 12 '08 #2
On Aug 12, 5:07*pm, * Tong * <sun_tong_...@u sers.sourceforg e.net>
wrote:
Hi,

I'm following the example in "C++ Templates: The Complete Guide",
section 5.4 Template Template Parameters.

It's basics/stack8.hpp example has a statement of "#include <allocator>",
but I got an error for it.
[snip]
allocator.cc:1: 23: error: allocator: No such file or directory
[...]

How to fix the above allocator.cc so that it compiles fine?
Use <memoryinstea d.

Cheers! --M
Aug 12 '08 #3

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

Similar topics

2
4421
by: Ralf Schneeweiß | last post by:
Hi, there is a book from Andre Wilms describing how to write allocators for STL containers. Unfortunately the MS VC++ Compiler is not supporting the full ANSI standard in the template part of the C++ programming language. This is the reason why the implementation proposal of Wilms is not working with this compiler. Is there anyone who knows a implementation proposal for an allocator working with VC++? Thanks
3
1880
by: Bernhard Kick | last post by:
Hi all, I saw this code in the book "Accelerated C++" (chapt 11, iirc): template <class T> class Vec { ... std::allocator<T> alloc; // object to handle memory allocation // ??would static member work here??: // static std::allocator<T> alloc;
3
1533
by: Orjan Westin | last post by:
Hi, I have an interesting (read frustrating) problem. I'm writing a generic container class, which holds data as well as links to other instances of itself, like this: template<class T> class node { public:
15
4277
by: Alex Vinokur | last post by:
I am looking for any custom allocator sample code for std::vector. Thanks. -- Alex Vinokur http://mathforum.org/library/view/10978.html http://sourceforge.net/users/alexvn
7
3081
by: Grahamo | last post by:
Hi, can anybody tell me where I can get the boiler plate code for std::allocator. I need to have my version of new and delete called and want to get reference code. My compilers headers are all over the place with #ifdefs and what not, I'd like a clean copy. thanks much
1
7298
by: sharmadeep1980 | last post by:
Hi All, I am facing a very unique problem while compling my project in "Release" build. The project is building in DEBUG mode but giving linking error on Release build. Here is the error: Creating library Release/fnimqcmd.lib and object Release/fnimqcmd.exp CoIMQCmd.obj : error LNK2001: unresolved external symbol
1
2804
by: xqxu.pzhou | last post by:
I wrote a simple allocator "myAlloc" under the g++ 3.2.3. When it is used by Vector, it works well. But when it is used by List, the codes have errors when compling. the error message is: "no matching function for call to myAlloc<std::_List_node<int> Then I added the following copy constructor to "myAlloc", now it works well. "template <typename U> myAlloc(const myAlloc<U>&) {}"
6
13861
by: Juha Nieminen | last post by:
I tested the speed of a simple program like this: //------------------------------------------------------------ #include <list> #include <boost/pool/pool_alloc.hpp> int main() { typedef std::list<intList_t; // default allocator //typedef std::list<int, boost::pool_allocator<int List_t;
16
2703
by: PeterAPIIT | last post by:
Hello all C++ expert programmer, i have wrote partial general allocator for my container. After reading standard C++ library and code guru article, i have several questions. 1. Why allocator write forward declaration then allocation for void* rather than directly wrote allocator first ?
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
10413
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
10145
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
9986
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
9021
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
7530
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
5551
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3707
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.