Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > template: no matching function call. Converting const value to constreference.

Reply
Thread Tools

template: no matching function call. Converting const value to constreference.

 
 
cablepuff@gmail.com
Guest
Posts: n/a
 
      12-06-2007
template <typename ContainerType>
ContainerType rsa_encrypt_list(const std::string&, const typename
ContainerType::reference, const typename ContainerType::reference);

const BigInteger e(boost::lexical_cast<BigInteger>(rsa_encrypts[2]));
const BigInteger
n(boost::lexical_cast<BigInteger>(rsa_encrypts[1]));
std::string infile(rsa_encrypts[0]);
boost::scoped_ptr<boost::filesystem::ifstream> encrypt_input(new
boost::filesystem::ifstream(infile));
const std::string
plaintext(std::istreambuf_iterator<char>(encrypt_i nput->rdbuf()),
std::istreambuf_iterator<char>());
std::list<BigInteger>
decrypted_list(encryptcpw::rsa_encrypt_list<std::l ist<BigInteger>
>(plaintext, e, n)); // this is line 64.


std::vector<BigInteger>(ciphertext).swap(ciphertex t);
// ... some code in between.
const std::string answer(encryptcpw::rsa_decrypt_list(ciphertext, d,
n)); // this is line 102.


error on gcc:
../cs512/c++/RsaEncrypt.cpp:64: error: no matching function for call to
'rsa_encr
ypt_list(const std::string&, const BigInteger&, const BigInteger&)'
../cs512/c++/RsaEncrypt.cpp:102: error: no matching function for call
to 'rsa_dec
rypt_list(std::vector<BigInteger, std::allocator<BigInteger> >&, const
BigIntege
r&, const BigInteger&)'


error on msvc:
../cs512/c++/RsaEncrypt.cpp(64) : error C2664:
'encryptcpw::rsa_encrypt_list' : cannot convert parameter 2 from
'const BigInteger' to 'BigInteger &'
Conversion loses qualifiers

Anybody know how to fix this.
 
Reply With Quote
 
 
 
 
tragomaskhalos
Guest
Posts: n/a
 
      12-06-2007
On Dec 6, 5:12 am, "(E-Mail Removed)" <(E-Mail Removed)> wrote:
> template <typename ContainerType>
> ContainerType rsa_encrypt_list(const std::string&, const typename
> ContainerType::reference, const typename ContainerType::reference);
>
> const BigInteger e(boost::lexical_cast<BigInteger>(rsa_encrypts[2]));
> const BigInteger
> n(boost::lexical_cast<BigInteger>(rsa_encrypts[1]));
> std::string infile(rsa_encrypts[0]);
> boost::scoped_ptr<boost::filesystem::ifstream> encrypt_input(new
> boost::filesystem::ifstream(infile));
> const std::string
> plaintext(std::istreambuf_iterator<char>(encrypt_i nput->rdbuf()),
> std::istreambuf_iterator<char>());
> std::list<BigInteger>
> decrypted_list(encryptcpw::rsa_encrypt_list<std::l ist<BigInteger>
>
> >(plaintext, e, n)); // this is line 64.

>
> std::vector<BigInteger>(ciphertext).swap(ciphertex t);
> // ... some code in between.
> const std::string answer(encryptcpw::rsa_decrypt_list(ciphertext, d,
> n)); // this is line 102.
>
> error on gcc:
> ./cs512/c++/RsaEncrypt.cpp:64: error: no matching function for call to
> 'rsa_encr
> ypt_list(const std::string&, const BigInteger&, const BigInteger&)'
> ./cs512/c++/RsaEncrypt.cpp:102: error: no matching function for call
> to 'rsa_dec
> rypt_list(std::vector<BigInteger, std::allocator<BigInteger> >&, const
> BigIntege
> r&, const BigInteger&)'
>
> error on msvc:
> ./cs512/c++/RsaEncrypt.cpp(64) : error C2664:
> 'encryptcpw::rsa_encrypt_list' : cannot convert parameter 2 from
> 'const BigInteger' to 'BigInteger &'
> Conversion loses qualifiers
>
> Anybody know how to fix this.


I believe the problem is here:

template <typename ContainerType>
ContainerType rsa_encrypt_list(const std::string&, const typename
ContainerType::reference, const typename ContainerType::reference);

... you can't const-qualify ContainerType::reference; Comeau online
gives warning "warning: type qualifiers are meaningless in this
declaration"

you need instead:
template <typename ContainerType>
ContainerType rsa_encrypt_list(const std::string&, typename
ContainerType::const_reference, typename
ContainerType::const_reference);

and define const_reference in your ContainerType(s) accordingly.


 
Reply With Quote
 
 
 
 
cablepuff@gmail.com
Guest
Posts: n/a
 
      12-07-2007
On Dec 6, 5:05 am, tragomaskhalos <(E-Mail Removed)>
wrote:
> On Dec 6, 5:12 am, "(E-Mail Removed)" <(E-Mail Removed)> wrote:
>
>
>
> > template <typename ContainerType>
> > ContainerType rsa_encrypt_list(const std::string&, const typename
> > ContainerType::reference, const typename ContainerType::reference);

>
> > const BigInteger e(boost::lexical_cast<BigInteger>(rsa_encrypts[2]));
> > const BigInteger
> > n(boost::lexical_cast<BigInteger>(rsa_encrypts[1]));
> > std::string infile(rsa_encrypts[0]);
> > boost::scoped_ptr<boost::filesystem::ifstream> encrypt_input(new
> > boost::filesystem::ifstream(infile));
> > const std::string
> > plaintext(std::istreambuf_iterator<char>(encrypt_i nput->rdbuf()),
> > std::istreambuf_iterator<char>());
> > std::list<BigInteger>
> > decrypted_list(encryptcpw::rsa_encrypt_list<std::l ist<BigInteger>

>
> > >(plaintext, e, n)); // this is line 64.

>
> > std::vector<BigInteger>(ciphertext).swap(ciphertex t);
> > // ... some code in between.
> > const std::string answer(encryptcpw::rsa_decrypt_list(ciphertext, d,
> > n)); // this is line 102.

>
> > error on gcc:
> > ./cs512/c++/RsaEncrypt.cpp:64: error: no matching function for call to
> > 'rsa_encr
> > ypt_list(const std::string&, const BigInteger&, const BigInteger&)'
> > ./cs512/c++/RsaEncrypt.cpp:102: error: no matching function for call
> > to 'rsa_dec
> > rypt_list(std::vector<BigInteger, std::allocator<BigInteger> >&, const
> > BigIntege
> > r&, const BigInteger&)'

>
> > error on msvc:
> > ./cs512/c++/RsaEncrypt.cpp(64) : error C2664:
> > 'encryptcpw::rsa_encrypt_list' : cannot convert parameter 2 from
> > 'const BigInteger' to 'BigInteger &'
> > Conversion loses qualifiers

>
> > Anybody know how to fix this.

>
> I believe the problem is here:
>
> template <typename ContainerType>
> ContainerType rsa_encrypt_list(const std::string&, const typename
> ContainerType::reference, const typename ContainerType::reference);
>
> .. you can't const-qualify ContainerType::reference; Comeau online
> gives warning "warning: type qualifiers are meaningless in this
> declaration"
>
> you need instead:
> template <typename ContainerType>
> ContainerType rsa_encrypt_list(const std::string&, typename
> ContainerType::const_reference, typename
> ContainerType::const_reference);
>
> and define const_reference in your ContainerType(s) accordingly.


thanks that fixes everything.
 
Reply With Quote
 
cablepuff@gmail.com
Guest
Posts: n/a
 
      12-07-2007
On Dec 6, 6:05 pm, "(E-Mail Removed)" <(E-Mail Removed)> wrote:
> On Dec 6, 5:05 am, tragomaskhalos <(E-Mail Removed)>
> wrote:
>
>
>
> > On Dec 6, 5:12 am, "(E-Mail Removed)" <(E-Mail Removed)> wrote:

>
> > > template <typename ContainerType>
> > > ContainerType rsa_encrypt_list(const std::string&, const typename
> > > ContainerType::reference, const typename ContainerType::reference);

>
> > > const BigInteger e(boost::lexical_cast<BigInteger>(rsa_encrypts[2]));
> > > const BigInteger
> > > n(boost::lexical_cast<BigInteger>(rsa_encrypts[1]));
> > > std::string infile(rsa_encrypts[0]);
> > > boost::scoped_ptr<boost::filesystem::ifstream> encrypt_input(new
> > > boost::filesystem::ifstream(infile));
> > > const std::string
> > > plaintext(std::istreambuf_iterator<char>(encrypt_i nput->rdbuf()),
> > > std::istreambuf_iterator<char>());
> > > std::list<BigInteger>
> > > decrypted_list(encryptcpw::rsa_encrypt_list<std::l ist<BigInteger>

>
> > > >(plaintext, e, n)); // this is line 64.

>
> > > std::vector<BigInteger>(ciphertext).swap(ciphertex t);
> > > // ... some code in between.
> > > const std::string answer(encryptcpw::rsa_decrypt_list(ciphertext, d,
> > > n)); // this is line 102.

>
> > > error on gcc:
> > > ./cs512/c++/RsaEncrypt.cpp:64: error: no matching function for call to
> > > 'rsa_encr
> > > ypt_list(const std::string&, const BigInteger&, const BigInteger&)'
> > > ./cs512/c++/RsaEncrypt.cpp:102: error: no matching function for call
> > > to 'rsa_dec
> > > rypt_list(std::vector<BigInteger, std::allocator<BigInteger> >&, const
> > > BigIntege
> > > r&, const BigInteger&)'

>
> > > error on msvc:
> > > ./cs512/c++/RsaEncrypt.cpp(64) : error C2664:
> > > 'encryptcpw::rsa_encrypt_list' : cannot convert parameter 2 from
> > > 'const BigInteger' to 'BigInteger &'
> > > Conversion loses qualifiers

>
> > > Anybody know how to fix this.

>
> > I believe the problem is here:

>
> > template <typename ContainerType>
> > ContainerType rsa_encrypt_list(const std::string&, const typename
> > ContainerType::reference, const typename ContainerType::reference);

>
> > .. you can't const-qualify ContainerType::reference; Comeau online
> > gives warning "warning: type qualifiers are meaningless in this
> > declaration"

>
> > you need instead:
> > template <typename ContainerType>
> > ContainerType rsa_encrypt_list(const std::string&, typename
> > ContainerType::const_reference, typename
> > ContainerType::const_reference);

>
> > and define const_reference in your ContainerType(s) accordingly.

>
> thanks that fixes everything.


now i got a new problem.
template <typename OutputIterator>
OutputIterator str_to_numlist(OutputIterator OutIt, const std::string&
s, typename OutputIterator::const_reference bound)
{
// some code.
}

template <typename ContainerType>
ContainerType encryptcpw::rsa_encrypt_list(const std::string& text,
typename ContainerType::const_reference e, typename
ContainerType::const_reference n)
{
typedef typename ContainerType::value_type T;
BOOST_STATIC_ASSERT(((std::numeric_limits<T>::is_i nteger) ||
(std::numeric_limits<T>::is_float)));
ContainerType encrypted_list;
encryptcpw::str_to_numlist(std::back_inserter(encr ypted_list),
text, n);
BOOST_FOREACH(T& val, encrypted_list)
{
val = encryptcpw::rsa_encrypt(val, e, n);
}
return encrypted_list;
}

my error is this
: error :
../cs512/c++/RsaEncrypt.cpp:64: instantiated from here
../cs512/c++/cppdef/rsa.cpp:205: error: no matching function for call
to 'str_to_
numlist(std::back_insert_iterator<std::list<BigInt eger,
std::allocator<BigIntege
r> > >, const std::basic_string<char, std::char_traits<char>,
std::allocator<cha
r> >&, const BigInteger&)'

Is it because the template parameter are different type that it gets
confuse? isn't const T& of std::back_inserter(std::list) same as const
T& of std::list
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
const vector<const MyType> Vs const vector<MyType> magnus.moraberg@gmail.com C++ 2 02-09-2009 10:45 PM
is const necessary in eg int compar(const void *, const void *) lovecreatesbeauty@gmail.c0m C Programming 26 11-10-2008 09:47 PM
const correctness - should C++ prefer const member over non-const? fungus C++ 13 10-31-2008 05:33 AM
const vector<A> vs vector<const A> vs const vector<const A> Javier C++ 2 09-04-2007 08:46 PM
Casting int'** to 'const int * const * const' dosn't work, why? Jonas.Holmsten@gmail.com C Programming 11 07-01-2007 06:16 PM



Advertisments