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

Compilation error

P: n/a
I'm implementing an algorithm that will fill a container with the same
item. However, my object creation function isn't working correctly.
This should auto detect the types based on the parameters it was passed.
But I must be missing something as it will not compile.

template<typename dest_t, typename src_t>
inline fill<dest_t, src_tmake_fill(dest_t& dest, src_t& src) //< error
{
return fill<dest_t, src_t>(src);
}

.../arrayTest1.h:68: error: expected init-declarator before '<' token
.../arrayTest1.h:68: error: expected `;' before '<' token

Thanks in advance.
Adrian
--
__________________________________________________ ___________________
\/Adrian_Hawryluk BSc. - Specialties: UML, OOPD, Real-Time Systems\/
\ My newsgroup writings are licensed under the Creative Commons /
\ Attribution-Noncommercial-Share Alike 3.0 License /
\_____[http://creativecommons.org/licenses/...sa/3.0/]_____/
\/______[blog:__http://adrians-musings.blogspot.com/]______\/
Mar 19 '07 #1
Share this Question
Share on Google+
9 Replies


P: n/a
Adrian Hawryluk wrote:
I'm implementing an algorithm that will fill a container with the same
item. However, my object creation function isn't working correctly.
This should auto detect the types based on the parameters it was passed.
But I must be missing something as it will not compile.

template<typename dest_t, typename src_t>
inline fill<dest_t, src_tmake_fill(dest_t& dest, src_t& src) //< error
{
return fill<dest_t, src_t>(src);
}

../arrayTest1.h:68: error: expected init-declarator before '<' token
../arrayTest1.h:68: error: expected `;' before '<' token

Thanks in advance.
Oh, here is the fill class that goes with it:

template <typename dest_t, typename src_t>
class fill
{
src_t const & value;
public:
fill(src_t const & value)
: value(value) {}

fill(fill const & f) : value(f.value) {}

void operator()(dest_t& dest)
{
// copy here
}
};
Adrian
--
__________________________________________________ ___________________
\/Adrian_Hawryluk BSc. - Specialties: UML, OOPD, Real-Time Systems\/
\ My newsgroup writings are licensed under the Creative Commons /
\ Attribution-Noncommercial-Share Alike 3.0 License /
\_____[http://creativecommons.org/licenses/...sa/3.0/]_____/
\/______[blog:__http://adrians-musings.blogspot.com/]______\/
Mar 19 '07 #2

P: n/a
Adrian Hawryluk wrote:
I'm implementing an algorithm that will fill a container with the same
item. However, my object creation function isn't working correctly.
This should auto detect the types based on the parameters it was passed.
But I must be missing something as it will not compile.

template<typename dest_t, typename src_t>
inline fill<dest_t, src_tmake_fill(dest_t& dest, src_t& src) //< error
{
return fill<dest_t, src_t>(src);
}

../arrayTest1.h:68: error: expected init-declarator before '<' token
../arrayTest1.h:68: error: expected `;' before '<' token
Look at the declaration immediately before the make_fill declaration.
Are you by any chance missing a semicolon?
Mar 19 '07 #3

P: n/a
red floyd wrote:
Adrian Hawryluk wrote:
>I'm implementing an algorithm that will fill a container with the same
item. However, my object creation function isn't working correctly.
This should auto detect the types based on the parameters it was
passed. But I must be missing something as it will not compile.

template<typename dest_t, typename src_t>
inline fill<dest_t, src_tmake_fill(dest_t& dest, src_t& src) //< error
{
return fill<dest_t, src_t>(src);
}

../arrayTest1.h:68: error: expected init-declarator before '<' token
../arrayTest1.h:68: error: expected `;' before '<' token

Look at the declaration immediately before the make_fill declaration.
Are you by any chance missing a semicolon?
Checked that already. The fill class that I posted is directly before
this function.
Adrian
--
__________________________________________________ ___________________
\/Adrian_Hawryluk BSc. - Specialties: UML, OOPD, Real-Time Systems\/
\ My newsgroup writings are licensed under the Creative Commons /
\ Attribution-Noncommercial-Share Alike 3.0 License /
\_____[http://creativecommons.org/licenses/...sa/3.0/]_____/
\/______[blog:__http://adrians-musings.blogspot.com/]______\/
Mar 19 '07 #4

P: n/a
Adrian Hawryluk wrote:
I'm implementing an algorithm that will fill a container with the same
item. However, my object creation function isn't working correctly.
This should auto detect the types based on the parameters it was passed.
But I must be missing something as it will not compile.

template<typename dest_t, typename src_t>
inline fill<dest_t, src_tmake_fill(dest_t& dest, src_t& src) //< error
{
return fill<dest_t, src_t>(src);
}

../arrayTest1.h:68: error: expected init-declarator before '<' token
../arrayTest1.h:68: error: expected `;' before '<' token

Thanks in advance.
Adrian
I don't get it. Under VC++ 6.0 it works (and that doesn't accept a
whole lot ;) lol jk) but g++ 3.4.4 (cygming special, gdc 0.12, using dmd
0.125), it chokes. Here is my test code that I transfered between the
two compilers. Nothing else in the file but this, so the only thing
that would go wrong is a link error because there is no main() function.

--------------------------------------------------------------------------
#include <vector>
#include <algorithm>
using namespace std;
template <typename dest_t, typename src_t>
class fill
{
src_t const & value;
public:
fill(src_t const & value)
: value(value) {}

void operator()(dest_t& dest)
{
}
};

template<typename dest_t, typename src_t>
inline fill<dest_t, src_t constmake_fill(dest_t& dest, src_t& src)
{
return fill<dest_t, src_t const>(src);
}

int main2(int argc, char* argv[])
{

vector<intaa;
aa.push_back(3);
aa.push_back(5);
int b = 3;
for_each(aa.begin(), aa.end(), make_fill(*aa.begin(), b));

return 0;
}
--------------------------------------------------------------------------
This is driving me nuts.
Adrian
--
__________________________________________________ ___________________
\/Adrian_Hawryluk BSc. - Specialties: UML, OOPD, Real-Time Systems\/
\ My newsgroup writings are licensed under the Creative Commons /
\ Attribution-Noncommercial-Share Alike 3.0 License /
\_____[http://creativecommons.org/licenses/...sa/3.0/]_____/
\/______[blog:__http://adrians-musings.blogspot.com/]______\/
Mar 20 '07 #5

P: n/a
Adrian Hawryluk wrote:
Adrian Hawryluk wrote:
>I'm implementing an algorithm that will fill a container with the same
item. However, my object creation function isn't working correctly.
This should auto detect the types based on the parameters it was
passed. But I must be missing something as it will not compile.

template<typename dest_t, typename src_t>
inline fill<dest_t, src_tmake_fill(dest_t& dest, src_t& src) //< error
{
return fill<dest_t, src_t>(src);
}

../arrayTest1.h:68: error: expected init-declarator before '<' token
../arrayTest1.h:68: error: expected `;' before '<' token

Thanks in advance.
Adrian

I don't get it. Under VC++ 6.0 it works (and that doesn't accept a
whole lot ;) lol jk) but g++ 3.4.4 (cygming special, gdc 0.12, using dmd
0.125), it chokes. Here is my test code that I transfered between the
two compilers. Nothing else in the file but this, so the only thing
that would go wrong is a link error because there is no main() function.

--------------------------------------------------------------------------
#include <vector>
#include <algorithm>
using namespace std;
template <typename dest_t, typename src_t>
class fill
{
src_t const & value;
public:
fill(src_t const & value)
: value(value) {}

void operator()(dest_t& dest)
{
}
};

template<typename dest_t, typename src_t>
inline fill<dest_t, src_t constmake_fill(dest_t& dest, src_t& src)
{
return fill<dest_t, src_t const>(src);
}

int main2(int argc, char* argv[])
{

vector<intaa;
aa.push_back(3);
aa.push_back(5);
int b = 3;
for_each(aa.begin(), aa.end(), make_fill(*aa.begin(), b));

return 0;
}
--------------------------------------------------------------------------
Don't know if it makes much of a diff, but change the second parameter
of make_fill to src_t const& src.
Mar 20 '07 #6

P: n/a
* Adrian Hawryluk:
>
#include <vector>
#include <algorithm>
using namespace std;
template <typename dest_t, typename src_t>
class fill
{
src_t const & value;
public:
fill(src_t const & value)
: value(value) {}

void operator()(dest_t& dest)
{
}
};

template<typename dest_t, typename src_t>
inline fill<dest_t, src_t constmake_fill(dest_t& dest, src_t& src)
{
return fill<dest_t, src_t const>(src);
}

int main2(int argc, char* argv[])
{

vector<intaa;
aa.push_back(3);
aa.push_back(5);
int b = 3;
for_each(aa.begin(), aa.end(), make_fill(*aa.begin(), b));

return 0;
}
--------------------------------------------------------------------------
This is driving me nuts.
'fill' is a standard library template function.

--
A: Because it messes up the order in which people normally read text.
Q: Why is it such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?
Mar 20 '07 #7

P: n/a
Alf P. Steinbach wrote:
* Adrian Hawryluk:
>>
#include <vector>
#include <algorithm>
using namespace std;
template <typename dest_t, typename src_t>
class fill
{
src_t const & value;
public:
fill(src_t const & value)
: value(value) {}
void operator()(dest_t& dest)
{
}
};

template<typename dest_t, typename src_t>
inline fill<dest_t, src_t constmake_fill(dest_t& dest, src_t& src)
{
return fill<dest_t, src_t const>(src);
}

int main2(int argc, char* argv[])
{
vector<intaa;
aa.push_back(3);
aa.push_back(5);
int b = 3;
for_each(aa.begin(), aa.end(), make_fill(*aa.begin(), b));

return 0;
}
--------------------------------------------------------------------------

This is driving me nuts.

'fill' is a standard library template function.
Yeah *sigh*, I just figured that out. I wish that the error message
came up on the class, and not on the function though.
Adrian
--
__________________________________________________ ___________________
\/Adrian_Hawryluk BSc. - Specialties: UML, OOPD, Real-Time Systems\/
\ My newsgroup writings are licensed under the Creative Commons /
\ Attribution-Noncommercial-Share Alike 3.0 License /
\_____[http://creativecommons.org/licenses/...sa/3.0/]_____/
\/______[blog:__http://adrians-musings.blogspot.com/]______\/
Mar 20 '07 #8

P: n/a
Adrian Hawryluk wrote:
Alf P. Steinbach wrote:
>* Adrian Hawryluk:
>>>
#include <vector>
#include <algorithm>
using namespace std;
template <typename dest_t, typename src_t>
class fill
{
src_t const & value;
public:
fill(src_t const & value)
: value(value) {}
void operator()(dest_t& dest)
{
}
};

template<typename dest_t, typename src_t>
inline fill<dest_t, src_t constmake_fill(dest_t& dest, src_t& src)
{
return fill<dest_t, src_t const>(src);
}

int main2(int argc, char* argv[])
{
vector<intaa;
aa.push_back(3);
aa.push_back(5);
int b = 3;
for_each(aa.begin(), aa.end(), make_fill(*aa.begin(), b));

return 0;
}
--------------------------------------------------------------------------

This is driving me nuts.

'fill' is a standard library template function.

Yeah *sigh*, I just figured that out. I wish that the error message
came up on the class, and not on the function though.
BTW, thanks for the help.
Adrian
--
__________________________________________________ ___________________
\/Adrian_Hawryluk BSc. - Specialties: UML, OOPD, Real-Time Systems\/
\ My newsgroup writings are licensed under the Creative Commons /
\ Attribution-Noncommercial-Share Alike 3.0 License /
\_____[http://creativecommons.org/licenses/...sa/3.0/]_____/
\/______[blog:__http://adrians-musings.blogspot.com/]______\/
Mar 20 '07 #9

P: n/a
Adrian Hawryluk wrote:
Alf P. Steinbach wrote:
>'fill' is a standard library template function.

Yeah *sigh*, I just figured that out. I wish that the error message
came up on the class, and not on the function though.
Adrian
BTW, thanks for the help.
Adrian
--
__________________________________________________ ___________________
\/Adrian_Hawryluk BSc. - Specialties: UML, OOPD, Real-Time Systems\/
\ My newsgroup writings are licensed under the Creative Commons /
\ Attribution-Noncommercial-Share Alike 3.0 License /
\_____[http://creativecommons.org/licenses/...sa/3.0/]_____/
\/______[blog:__http://adrians-musings.blogspot.com/]______\/
Mar 20 '07 #10

This discussion thread is closed

Replies have been disabled for this discussion.