472,791 Members | 1,600 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,791 software developers and data experts.

Boost compile error when a object of type pool is contained in another class

Hello,
I am looking for a little bit of help. I am trying to create a
dynamically allocated object which contains one or more objects of
type boost::pool<>. I get a compiler error when an object of this type
is contained in my class and am not sure why. To be honest I have a
little but not a lot of experience with templates and it could simply
be obvious to a more experienced template user; however, the answer
escapes me.

Here is a sample code snippet:

#include <boost/pool/pool.hpp>
#include <boost/pool/singleton_pool.hpp>

struct Foobar
{
boost::pool<p(sizeof(int)); // this is line 182

};

boost::pool<yp(512);

int main()
{
Foobar foobar;

printf( "%u\n", sizeof( boost::pool<>(512) ) );

return( 0 );
}

----------------------
Here is the error message:
ramMgr.cxx:182: error: expected identifier before #sizeof#
ramMgr.cxx:182: error: expected #,# or #...# before #sizeof#
---------------------------
compiler & version
g++ -v
gcc version 4.1.1 20060724 (4.1.1-3mdk)
Thanks,
Parker

Jun 13 '07 #1
5 2778
mackenzie wrote:
Hello,
I am looking for a little bit of help. I am trying to create a
dynamically allocated object which contains one or more objects of
type boost::pool<>. I get a compiler error when an object of this type
is contained in my class and am not sure why. To be honest I have a
little but not a lot of experience with templates and it could simply
be obvious to a more experienced template user; however, the answer
escapes me.

Here is a sample code snippet:

#include <boost/pool/pool.hpp>
#include <boost/pool/singleton_pool.hpp>

struct Foobar
{
boost::pool<p(sizeof(int)); // this is line 182
What's the 'sizeof' for? Are you trying to initialise it? If so,
initialisation of members belongs to constructor initialiser list.
If you were trying to declare an array, then replace parentheses
with brackets. Most likely you just need to lose the parentheses
and the expression inside them.
>
};

boost::pool<yp(512);

int main()
{
Foobar foobar;

printf( "%u\n", sizeof( boost::pool<>(512) ) );

return( 0 );
}

----------------------
Here is the error message:
ramMgr.cxx:182: error: expected identifier before #sizeof#
ramMgr.cxx:182: error: expected #,# or #...# before #sizeof#
---------------------------
compiler & version
g++ -v
gcc version 4.1.1 20060724 (4.1.1-3mdk)
Thanks,
Parker
V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
Jun 13 '07 #2
On Jun 13, 4:54 pm, "Victor Bazarov" <v.Abaza...@comAcast.netwrote:
mackenzie wrote:
Hello,
I am looking for a little bit of help. I am trying to create a
dynamically allocated object which contains one or more objects of
type boost::pool<>. I get a compiler error when an object of this type
is contained in my class and am not sure why. To be honest I have a
little but not a lot of experience with templates and it could simply
be obvious to a more experienced template user; however, the answer
escapes me.
Here is a sample code snippet:
#include <boost/pool/pool.hpp>
#include <boost/pool/singleton_pool.hpp>
struct Foobar
{
boost::pool<p(sizeof(int)); // this is line 182

What's the 'sizeof' for? Are you trying to initialise it? If so,
initialisation of members belongs to constructor initialiser list.
If you were trying to declare an array, then replace parentheses
with brackets. Most likely you just need to lose the parentheses
and the expression inside them.


};
boost::pool<yp(512);
int main()
{
Foobar foobar;
printf( "%u\n", sizeof( boost::pool<>(512) ) );
return( 0 );
}
----------------------
Here is the error message:
ramMgr.cxx:182: error: expected identifier before #sizeof#
ramMgr.cxx:182: error: expected #,# or #...# before #sizeof#
---------------------------
compiler & version
g++ -v
gcc version 4.1.1 20060724 (4.1.1-3mdk)
Thanks,
Parker

V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
Thanks for responding.

What I thought I was doing was creating a member of Foobar named p of
type boost::pool<which takes a size_type as an argument to the
constructor. It seems to work in the global name space; however, when
I put it into a structure or class I get the error.
>From : http://www.boost.org/libs/pool/doc/interfaces/pool.html
template <typename UserAllocator = default_user_allocator_new_delete>
class pool
{...
explicit pool(size_type requested_size);
};

Perhaps after the drive home and a clearer head I will stare at it
some more with your suggestion in mind and the answer will be a little
more obvious.

Thanks,
Parker

Jun 13 '07 #3
mackenzie wrote:
On Jun 13, 4:54 pm, "Victor Bazarov" <v.Abaza...@comAcast.netwrote:
>mackenzie wrote:
>>Hello,
I am looking for a little bit of help. I am trying to create a
dynamically allocated object which contains one or more objects of
type boost::pool<>. I get a compiler error when an object of this
type is contained in my class and am not sure why. To be honest I
have a little but not a lot of experience with templates and it
could simply be obvious to a more experienced template user;
however, the answer escapes me.
>>Here is a sample code snippet:
>>#include <boost/pool/pool.hpp>
#include <boost/pool/singleton_pool.hpp>
>>struct Foobar
{
boost::pool<p(sizeof(int)); // this is line 182

What's the 'sizeof' for? Are you trying to initialise it? If so,
initialisation of members belongs to constructor initialiser list.
If you were trying to declare an array, then replace parentheses
with brackets. Most likely you just need to lose the parentheses
and the expression inside them.
[..]

What I thought I was doing was creating a member of Foobar named p of
type boost::pool<which takes a size_type as an argument to the
constructor.
You're trying to provide a particular argument in a declaration.
That's not how you initialise the member. Please read about
constructors (of classes) and the _member_initialiser_lists_.
It seems to work in the global name space; however, when
I put it into a structure or class I get the error.
>From : http://www.boost.org/libs/pool/doc/interfaces/pool.html
template <typename UserAllocator = default_user_allocator_new_delete>
class pool
{...
explicit pool(size_type requested_size);
};

Perhaps after the drive home and a clearer head I will stare at it
some more with your suggestion in mind and the answer will be a little
more obvious.

Thanks,
Parker
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
Jun 14 '07 #4
Thank you Victor.

That makes perfect sense. I was looking at it as if it was being
passed in as a template argument. When in fact it is similar to any
other class.

Thanks again,
Parker

Jun 14 '07 #5
On Jun 14, 7:34 am, mackenzie <themackenziefam...@gmail.comwrote:
Thank you Victor.

That makes perfect sense. I was looking at it as if it was being
passed in as a template argument. When in fact it is similar to any
other class.

Thanks again,
Parker
For completeness, in case someone else has a similar question in the
future, the following is the corrected code:

struct Foobar
{
boost::pool<p; // this was line 182

Foobar() : p( 5 ) {}
};

Reference: 10.4.6.1 Necessary Member Initialization; The C++
Programming Language; Bjarne Stroustrup; May 2004

Thanks again Victor.
Jun 14 '07 #6

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

Similar topics

205
by: Jeremy Siek | last post by:
CALL FOR PAPERS/PARTICIPATION C++, Boost, and the Future of C++ Libraries Workshop at OOPSLA October 24-28, 2004 Vancouver, British Columbia, Canada http://tinyurl.com/4n5pf Submissions
17
by: newbiecpp | last post by:
I have hard time to understand run-time environment. Let assume that I have a program that has a simple variable alpha. When this variable is statically allocated, the compiler can use the...
6
by: Peter Frost | last post by:
Please help I don't know if this is possible but what I would really like to do is to use On Error Goto to capture the code that is being executed when an error occurs. Any help would be much...
0
by: ufnuceda | last post by:
Hello everyone, I was wondering if any of you have some experience with the boost library. I am having trouble compiling code with it. Since boost is being used a lot these days I thought some...
4
by: tony | last post by:
Hello! My question is about calling this method CollectData below but I get a compile error that I shouldn't have because the type parameter is correct. The compile error is the following:...
1
by: Noah Roberts | last post by:
Trying to use boost::function in a C++/CLI program. Here is code: pragma once #include <boost/function.hpp> #include <boost/shared_ptr.hpp> #include <vector> using namespace System;
4
by: silverburgh.meryl | last post by:
I have code which uses Boost lambda in a template like this: using namespace boost::lambda; template<class T> bool lessThanXY( T& src, T& dest ) { return (src.getY() < dest.getY()); } ...
1
by: werasm | last post by:
Hi, This is not boost related per sé, therefore I'm posing the question here. I need to do many small object allocations, and I'm considering using boost::pool for this. I've contemplated...
0
by: varnie | last post by:
hell-o !~ i faced weird problem during usage boost::pool_allocator. after i've changed: typedef boost::shared_ptr< param > ParamPtr; typedef std::vector< ParamPtr > ParamPtrVector; with:
3
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 2 August 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
by: erikbower65 | last post by:
Using CodiumAI's pr-agent is simple and powerful. Follow these steps: 1. Install CodiumAI CLI: Ensure Node.js is installed, then run 'npm install -g codiumai' in the terminal. 2. Connect to...
0
by: erikbower65 | last post by:
Here's a concise step-by-step guide for manually installing IntelliJ IDEA: 1. Download: Visit the official JetBrains website and download the IntelliJ IDEA Community or Ultimate edition based on...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Sept 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
by: Taofi | last post by:
I try to insert a new record but the error message says the number of query names and destination fields are not the same This are my field names ID, Budgeted, Actual, Status and Differences ...
14
DJRhino1175
by: DJRhino1175 | last post by:
When I run this code I get an error, its Run-time error# 424 Object required...This is my first attempt at doing something like this. I test the entire code and it worked until I added this - If...
0
by: Rina0 | last post by:
I am looking for a Python code to find the longest common subsequence of two strings. I found this blog post that describes the length of longest common subsequence problem and provides a solution in...
0
by: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
0
by: Mushico | last post by:
How to calculate date of retirement from date of birth

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.