By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
457,864 Members | 1,242 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 457,864 IT Pros & Developers. It's quick & easy.

compile time dependencies

P: n/a
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
Share this Question
Share on Google+
7 Replies


P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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 discussion thread is closed

Replies have been disabled for this discussion.