468,484 Members | 2,041 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,484 developers. It's quick & easy.

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 1477
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 discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by at14 | last post: by
3 posts views Thread by Grzegorz Dostatni | last post: by
1 post views Thread by Scott Brady Drummonds | last post: by
4 posts views Thread by Jan Bares | last post: by
reply views Thread by Scott F K Hooper | last post: by
2 posts views Thread by wxforecaster | last post: by
12 posts views Thread by mrbog | last post: by
reply views Thread by NPC403 | last post: by
2 posts views Thread by gieforce | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.