473,513 Members | 2,425 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

compile time dependencies

Hi

I can't compile

//#include <boost/function.hpp>

class boost::function;

UIStl * LoadStlFromAnotherProject(const CString & i_project_name,
boost::function<bool (MSAXReader &,UIObject *)i_func_compare);
1. Parameter and return types need only to be forward-declared.
(Herb Sutter , Exceptional C++: 47 Engineering Puzzles, Programming
Problems, and Solutions, Item 26)

Can anybody tell me correct syntax?

Thanks,

Yurij

Nov 15 '07 #1
7 1721
yurec wrote:
Hi

I can't compile

//#include <boost/function.hpp>

class boost::function;

UIStl * LoadStlFromAnotherProject(const CString & i_project_name,
boost::function<bool (MSAXReader &,UIObject *)i_func_compare);
1. Parameter and return types need only to be forward-declared.
(Herb Sutter , Exceptional C++: 47 Engineering Puzzles, Programming
Problems, and Solutions, Item 26)

Can anybody tell me correct syntax?
You have to include the header, because you are instantiating a template
class.

Regards,

Zeppe
Nov 15 '07 #2
yurec wrote:
Hi

I can't compile

//#include <boost/function.hpp>

class boost::function;

UIStl * LoadStlFromAnotherProject(const CString & i_project_name,
boost::function<bool (MSAXReader &,UIObject *)i_func_compare);
1. Parameter and return types need only to be forward-declared.
(Herb Sutter , Exceptional C++: 47 Engineering Puzzles, Programming
Problems, and Solutions, Item 26)

Can anybody tell me correct syntax?
namespace NS {
template <class Tclass Func;
}

void f(NS::Func<int>& f) {}
// ^^ reference or pointer

int main() { }
Nov 15 '07 #3
On Nov 15, 11:44 am, Zeppe
<ze...@remove.all.this.long.comment.yahoo.itwrot e:
yurec wrote:
Hi
I can't compile
//#include <boost/function.hpp>
class boost::function;
UIStl * LoadStlFromAnotherProject(const CString & i_project_name,
boost::function<bool (MSAXReader &,UIObject *)i_func_compare);
1. Parameter and return types need only to be forward-declared.
(Herb Sutter , Exceptional C++: 47 Engineering Puzzles, Programming
Problems, and Solutions, Item 26)
Can anybody tell me correct syntax?

You have to include the header, because you are instantiating a template
class.

Regards,

Zeppe- Hide quoted text -

- Show quoted text -

Could you kindly explain wy do we need detailed info about class when
instantiating template class while it's enough declaration when using
non-template class?
Nov 15 '07 #4
yurec wrote:
Could you kindly explain wy do we need detailed info about class when
instantiating template class while it's enough declaration when using
non-template class?
A template is a sort of compiler macro; the compiler can't expand the
macro (= instantiate the template) when it doesn't know about it yet.
Nov 15 '07 #5
On Nov 15, 1:37 pm, Matthias Buelow <m...@incubus.dewrote:
yurec wrote:
Could you kindly explain wy do we need detailed info about class when
instantiating template class while it's enough declaration when using
non-template class?

A template is a sort of compiler macro; the compiler can't expand the
macro (= instantiate the template) when it doesn't know about it yet.
ok, seems very clear. thanks.
Nov 15 '07 #6
Zeppe wrote:
yurec wrote:
>Hi

I can't compile

//#include <boost/function.hpp>

class boost::function;

UIStl * LoadStlFromAnotherProject(const CString & i_project_name,
boost::function<bool (MSAXReader &,UIObject *)i_func_compare);
1. Parameter and return types need only to be forward-declared.
(Herb Sutter , Exceptional C++: 47 Engineering Puzzles, Programming
Problems, and Solutions, Item 26)

Can anybody tell me correct syntax?

You have to include the header, because you are instantiating a template
class.
It's not necessary

<std>
14.7.3/10
A template-id that names a class template explicit specialization that
has been declared but not defined can be used exactly like the names of
other incompletely-defined classes (3.9). [Example:
template<class Tclass X; // X is a class template
template<class X<int>;
X<int>* p; // OK: pointer to declared class X<int>
X<intx; // error: object of incomplete class X<int>
—end example]
</std>
here is how what the op want,
anyway, I don't suggest this :-)

<code>
namespace boost {
template <class, class>
class function;
}

#include <boost/function.hpp>

void invoke(boost::function<int(int)>& f) {
f(10);
}

#include <iostream>

int f(int i) { std::cout << i << std::endl; return i; }

int main() {
boost::function<int(int)fobj(f);
invoke(fobj);
}
</code>
Nov 15 '07 #7
On Thu, 15 Nov 2007 00:25:19 -0800, yurec wrote:
Hi

I can't compile

//#include <boost/function.hpp>

class boost::function;

UIStl * LoadStlFromAnotherProject(const CString & i_project_name,
boost::function<bool (MSAXReader &,UIObject *)i_func_compare);
1. Parameter and return types need only to be forward-declared.
(Herb Sutter , Exceptional C++: 47 Engineering Puzzles, Programming
Problems, and Solutions, Item 26)

Can anybody tell me correct syntax?
There are two problems:
1) Compiler should fail on:
class boost::function;

because the proper syntax for declaring _class_ in namespace is
namespace boost
{
class function;
}

2) Unfortunately boost::function is not a class but a class template. And
you need to know the number of template parameters it takes to forward
declare it. Finding it out might be painful and you are not guaranteed
the number of parameters won't change in next versions. So it's much
better to include the header.
--
Tadeusz B. Kopec (tk****@NOSPAMPLEASElife.pl)
You won't skid if you stay in a rut.
-- Frank Hubbard
Nov 15 '07 #8

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

Similar topics

1
2133
by: at14 | last post by:
To whom it may concern, My group has python version 2.2.1 installed on a linux system. I am in the process of trying to run some software that requires a module called time. For some reason,...
3
2842
by: Grzegorz Dostatni | last post by:
Cheers. First what I am trying to do: I am trying to create a version of pytho23.dll that contains everything inside of it. It is staticaly linked. It also needs to contain the qt library. For...
1
1780
by: Scott Brady Drummonds | last post by:
Hi, everyone, I'm working on a software project that contains some C++ code that I would like to be common to two separate projects. Ideally, I'd like to have each of these separate projects...
4
1517
by: Jan Bares | last post by:
Hi, I have a resource.rc in my project. The resource.rc includes another.rc file in "Compile time directives". Unfortunately, when I change the another.rc, the resources are not compiled, I have...
0
914
by: Scott F K Hooper | last post by:
I get this error on compile of my vb/asp.net app: Could not load file or assembly 'WebChart, Version=3.1.0.0, Culture=neutral, PublicKeyToken=null' or one of its dependencies. Failed to grant...
0
1267
by: Symon | last post by:
I've got a web service project that was built under VS 2003 which has a SoapExtension in the project. The SoapExtension is registered in the <soapExtensionTypes> element of the web.config and has...
2
1171
by: wxforecaster | last post by:
I'm a VB programmer by trade (hold the tomatoes please), and I have a very small C utility that I need to compile into a windows executable. It's a widely used utility in academia for...
12
3411
by: mrbog | last post by:
For those of you with red hat or fedora, do you yum install php or do you compile it?
16
9124
by: pereges | last post by:
Do you see anything wrong about this method ? For eg. I write a shell script a.sh containing : cc -o test file1.c file2.c file3.c and then execute the shell script ( sh a.sh) to compile and...
0
7264
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,...
0
7166
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...
0
7386
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,...
0
7534
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...
0
5689
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,...
1
5094
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...
0
4749
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...
0
1601
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 ...
0
459
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.