472,330 Members | 1,429 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,330 software developers and data experts.

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

Hello,
here is a code snippet showning my problem :

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

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

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

TClass2<inttest1;

int* ptr = new int;

test1.Process(ptr);

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 8969
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<typename _K>
class TClass1
{
public:
void Process(const _K& arg) const
{

}
};
template<typename _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.Process', 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*_class1;

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

TClass2<inttest1;

int* ptr = new int;

test1.Process(ptr);

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*>::Process(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...@comAcast.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<typename _K>
class TClass1
{
public:
void Process(const _K& arg) const
{
}
};
template<typename _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.Process', 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*_class1;
};
int main(int argc, char* argv[])
{
TClass2<inttest1;
int* ptr = new int;
test1.Process(ptr);
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*>::Process(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
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...
14
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...
2
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,...
9
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...
2
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...
9
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...
11
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...
2
by: cablepuff | last post by:
template <typename ContainerType> ContainerType rsa_encrypt_list(const std::string&, const typename ContainerType::reference, const typename...
2
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
by: tammygombez | last post by:
Hey fellow JavaFX developers, I'm currently working on a project that involves using a ComboBox in JavaFX, and I've run into a bit of an issue....
0
by: tammygombez | last post by:
Hey everyone! I've been researching gaming laptops lately, and I must say, they can get pretty expensive. However, I've come across some great...
0
by: concettolabs | last post by:
In today's business world, businesses are increasingly turning to PowerApps to develop custom business applications. PowerApps is a powerful tool...
0
by: Kemmylinns12 | last post by:
Blockchain technology has emerged as a transformative force in the business world, offering unprecedented opportunities for innovation and...
0
by: CD Tom | last post by:
This happens in runtime 2013 and 2016. When a report is run and then closed a toolbar shows up and the only way to get it to go away is to right...
0
by: CD Tom | last post by:
This only shows up in access runtime. When a user select a report from my report menu when they close the report they get a menu I've called Add-ins...
0
jalbright99669
by: jalbright99669 | last post by:
Am having a bit of a time with URL Rewrite. I need to incorporate http to https redirect with a reverse proxy. I have the URL Rewrite rules made...
2
by: Matthew3360 | last post by:
Hi, I have a python app that i want to be able to get variables from a php page on my webserver. My python app is on my computer. How would I make it...
0
by: AndyPSV | last post by:
HOW CAN I CREATE AN AI with an .executable file that would suck all files in the folder and on my computerHOW CAN I CREATE AN AI with an .executable...

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.