473,224 Members | 1,483 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

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 1710
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
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
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
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
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
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
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
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
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
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
by: VivesProcSPL | last post by:
Obviously, one of the original purposes of SQL is to make data query processing easy. The language uses many English-like terms and syntax in an effort to make it easy to learn, particularly for...
3
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 3 Jan 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). For other local times, please check World Time Buddy In...
0
by: mar23 | last post by:
Here's the situation. I have a form called frmDiceInventory with subform called subfrmDice. The subform's control source is linked to a query called qryDiceInventory. I've been trying to pick up the...
0
by: abbasky | last post by:
### Vandf component communication method one: data sharing ​ Vandf components can achieve data exchange through data sharing, state sharing, events, and other methods. Vandf's data exchange method...
2
by: jimatqsi | last post by:
The boss wants the word "CONFIDENTIAL" overlaying certain reports. He wants it large, slanted across the page, on every page, very light gray, outlined letters, not block letters. I thought Word Art...
0
by: stefan129 | last post by:
Hey forum members, I'm exploring options for SSL certificates for multiple domains. Has anyone had experience with multi-domain SSL certificates? Any recommendations on reliable providers or specific...
0
Git
by: egorbl4 | last post by:
Скачал я git, хотел начать настройку, а там вылезло вот это Что это? Что мне с этим делать? ...
1
by: davi5007 | last post by:
Hi, Basically, I am trying to automate a field named TraceabilityNo into a web page from an access form. I've got the serial held in the variable strSearchString. How can I get this into the...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....

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.