473,545 Members | 2,025 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Template : cannot convert parameter 1 from const * to *const & ?

Hello,
here is a code snippet showning my problem :

template<typena me _K>
class TClass1
{
public:
void Process(const _K& arg) const
{

}
};
template<typena me _I>
class TClass2
{
public:
void Process(const _I* & arg) const
{
_class1.Process (arg);
}
protected:
TClass1<_I*_cla ss1;

};
int main(int argc, char* argv[])
{

TClass2<inttest 1;

int* ptr = new int;

test1.Process(p tr);

delete ptr;

return 0;
}

This code does not compile, I have got the following error message :
"cannot convert parameter 1 from 'const int *' to 'int *const & '"
Any idea?I have noted that if I declare _class1 as TClass1<const _I*>,
it is working...
Regards!

May 23 '07 #1
2 9147
na************* ****@gmail.com wrote:
Hello,
here is a code snippet showning my problem :
The first problem is all those underscores. Why do you think
you need them at all?
>
template<typena me _K>
class TClass1
{
public:
void Process(const _K& arg) const
{

}
};
template<typena me _I>
class TClass2
{
public:
void Process(const _I* & arg) const
{
_class1.Process (arg);
'_I' is 'int', right? '_class1' then 'TClass1<int*>' , right?
Then its template argument (the '_K' inside) is 'int*', right?
What's the specification of the 'Process' member, then?

void TClass1<int*>:: Process(int* const&);

So, when you're calling '_class1.Proces s', what argument type
are you giving? '_I const * &'. Considering '_I' is 'int',
you are trying to call 'Process' with

int const * &

instead of

int * const &

.. Decide on the position of the const. Or drop the * from
the definition of '_class1'.
}
protected:
TClass1<_I*_cla ss1;

};
int main(int argc, char* argv[])
{

TClass2<inttest 1;

int* ptr = new int;

test1.Process(p tr);

delete ptr;

return 0;
}

This code does not compile, I have got the following error message :
"cannot convert parameter 1 from 'const int *' to 'int *const & '"
Any idea?I have noted that if I declare _class1 as TClass1<const _I*>,
it is working...
Right. If you add a const at the _I, the function you're trying to
call is

void TClass1<int const*>::Proces s(int const* const&);

which is fine. Its argument ('int const* const&') is compatible with
'int const* &' you're trying to give it.

V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
May 23 '07 #2
On 23 mai, 17:22, nassim.bouayad. a...@gmail.com wrote:
On 23 mai, 16:59, "Victor Bazarov" <v.Abaza...@com Acast.netwrote:


nassim.bouayad. a...@gmail.com wrote:
Hello,
here is a code snippet showning my problem :
The first problem is all those underscores. Why do you think
you need them at all?
template<typena me _K>
class TClass1
{
public:
void Process(const _K& arg) const
{
}
};
template<typena me _I>
class TClass2
{
public:
void Process(const _I* & arg) const
{
_class1.Process (arg);
'_I' is 'int', right? '_class1' then 'TClass1<int*>' , right?
Then its template argument (the '_K' inside) is 'int*', right?
What's the specification of the 'Process' member, then?
void TClass1<int*>:: Process(int* const&);
So, when you're calling '_class1.Proces s', what argument type
are you giving? '_I const * &'. Considering '_I' is 'int',
you are trying to call 'Process' with
int const * &
instead of
int * const &
. Decide on the position of the const. Or drop the * from
the definition of '_class1'.
}
protected:
TClass1<_I*_cla ss1;
};
int main(int argc, char* argv[])
{
TClass2<inttest 1;
int* ptr = new int;
test1.Process(p tr);
delete ptr;
return 0;
}
This code does not compile, I have got the following error message :
"cannot convert parameter 1 from 'const int *' to 'int *const & '"
Any idea?I have noted that if I declare _class1 as TClass1<const _I*>,
it is working...
Right. If you add a const at the _I, the function you're trying to
call is
void TClass1<int const*>::Proces s(int const* const&);
which is fine. Its argument ('int const* const&') is compatible with
'int const* &' you're trying to give it.
V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask- Masquer le texte des messages précédents -
- Afficher le texte des messages précédents -- Masquer le texte desmessages précédents -
- Afficher le texte des messages précédents -

Thank you!- Masquer le texte des messages précédents -

- Afficher le texte des messages précédents -
Hello,
I still have a problem.The exemple that I gave is trivial,but how can
I do if I need to use this,for stl containers?For exemple,if I want a
multimap which key is a pointer on a type?!This may cause problems
because I need to store pointers to non const objects...
Any idea?
Thank you in advance.
Regards.

May 24 '07 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
2662
by: Thomas Matthews | last post by:
Hi, I would like to apply inheritance to a template parameter, but my design fails to compile: cannot initialize one template class with child child parameterized class. I'll explain... Given: #include <string> // Parent class
14
2872
by: Bart Samwel | last post by:
Hi everybody, I would really like some help explaining this apparent discrepancy, because I really don't get it. Here is the snippet: void foo(int&); void foo(int const&); template<typename T>
2
408
by: jeffp | last post by:
The following snipped of code won't compiler under either MSVC 7 or GCC (not sure which version). I can't think of any reason it should not work, anybody have any ideas: template <typename T> class Link { public: T *m_next; };
9
2750
by: Marek Vondrak | last post by:
Hello. I have written the following program and am curious why it prints "1" "2". What are the exact effects of explicitly providing function template parameters at the call? Is the second assign() function really a specialization of the first assign() or is it an assign() overload? Thank you. -- Marek
2
3914
by: Nick | last post by:
I'm learning C++ and ran into a compile error using Visual C++ 2005 Express on the following example program (located at http://www.cplusplus.com/doc/tutorial/templates.html): // template specialization #include <iostream> using namespace std; template <class T> class container {
9
2741
by: Mike | last post by:
Hi, Just a simple question: why the compiler doesn't report error when accessing a private member function inside a function having template type ? For example: #include<iostream> using namespace std;
11
2729
by: mathieu | last post by:
Hi there, I don't think I'll be able to describe my issue correctly, so instead I'll just give a pseudo C++ code I am struggling with. Basically I am looking for a 'pure virtual template' function that I would be able to declare in the base class (*). Thanks for suggestions, -Mathieu
2
6555
by: cablepuff | last post by:
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)); const BigInteger n(boost::lexical_cast<BigInteger>(rsa_encrypts)); std::string infile(rsa_encrypts);...
2
6608
by: Clyde | last post by:
Hi, what i'm trying to do is: /////////////// Code Start template <class TType, int* p = 0> class Template { public:
0
7479
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7411
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7669
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
7926
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
5343
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
4962
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3450
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1901
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1028
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.