Hi there,
I am trying to declare a function that takes a std::list<param eter.
I want this function to have an empty list as a default parameter.
It's a template function also. Currently i am stuck because my
compiler does not find a matching function when i do a call.
here is my code:
// ############## code begins
#include <list>
using namespace std;
template<typena me T>
int* f(const int*,
const int*,
const int*,
list<pair<int, T =list<pair<int, int () );
int main (int argc, char* argv)
{
int* c, t, i;
int* result = f(c, t, i);
}
template<typena me T>
int* f(const int* c, const int* t, const int* i,
list<pair<int, T )
{
return (int *) 0;
}
// ############## code ends
compiler says
testcase.cpp: In function 'int main(int, char*)':
testcase.cpp:16 : error: no matching function for call to 'f(int*&, int&,
int&)'
compiler version is g++ 4.0.2. I guess i am doing wrong with the syntax
here. Would be nice if someone knows how to do this right... thanks in
advance.
matthias 11 2354
On Jun 14, 5:20 pm, Matthias Pfeifer <pfe...@web.dew rote:
Hi there,
I am trying to declare a function that takes a std::list<param eter.
I want this function to have an empty list as a default parameter.
It's a template function also. Currently i am stuck because my
compiler does not find a matching function when i do a call.
here is my code:
// ############## code begins
#include <list>
using namespace std;
template<typena me T>
int* f(const int*,
const int*,
const int*,
list<pair<int, T =list<pair<int, int () );
int main (int argc, char* argv)
{
int* c, t, i;
int* result = f(c, t, i);
}
template<typena me T>
int* f(const int* c, const int* t, const int* i,
list<pair<int, T )
{
return (int *) 0;}
// ############## code ends
compiler says
testcase.cpp: In function 'int main(int, char*)':
testcase.cpp:16 : error: no matching function for call to 'f(int*&, int&,
int&)'
compiler version is g++ 4.0.2. I guess i am doing wrong with the syntax
here. Would be nice if someone knows how to do this right... thanks in
advance.
matthias
Dear Matthias,
The reason for the error is you didnt specify the type.
A small modification can correct this problem.
I just specified the type also before calling the function.
#include <list>
using namespace std;
template<typena me T>
int* f(const int*,
const int*,
const int*,
list<pair<int, T =list<pair<int, int () );
int main (int argc, char* argv)
{
int* c, *t, *i;
int* result = f<int>(c, t, i);
}
template<typena me T>
int* f(const int* c, const int* t, const int* i,
list<pair<int, T )
{
return (int *) 0;
}
Thanks and regards,
Amal P.
On Jun 14, 6:09 pm, Amal P <enjoyam...@gma il.comwrote:
On Jun 14, 5:20 pm, Matthias Pfeifer <pfe...@web.dew rote:
Hi there,
I am trying to declare a function that takes a std::list<param eter.
I want this function to have an empty list as a default parameter.
It's a template function also. Currently i am stuck because my
compiler does not find a matching function when i do a call.
here is my code:
// ############## code begins
#include <list>
using namespace std;
template<typena me T>
int* f(const int*,
const int*,
const int*,
list<pair<int, T =list<pair<int, int () );
int main (int argc, char* argv)
{
int* c, t, i;
int* result = f(c, t, i);
}
template<typena me T>
int* f(const int* c, const int* t, const int* i,
list<pair<int, T )
{
return (int *) 0;}
// ############## code ends
compiler says
testcase.cpp: In function 'int main(int, char*)':
testcase.cpp:16 : error: no matching function for call to 'f(int*&, int&,
int&)'
compiler version is g++ 4.0.2. I guess i am doing wrong with the syntax
here. Would be nice if someone knows how to do this right... thanks in
advance.
matthias
Dear Matthias,
The reason for the error is you didnt specify the type.
A small modification can correct this problem.
I just specified the type also before calling the function.
#include <list>
using namespace std;
template<typena me T>
int* f(const int*,
const int*,
const int*,
list<pair<int, T =list<pair<int, int () );
int main (int argc, char* argv)
{
int* c, *t, *i;
int* result = f<int>(c, t, i);
}
template<typena me T>
int* f(const int* c, const int* t, const int* i,
list<pair<int, T )
{
return (int *) 0;
}
Thanks and regards,
Amal P.
Dear Matthias,
I hope you write this code just to test the default parameter.
It wont be possible to run this code now also because none of the
pointers point to a valid memory.
Thanks and regards,
Amal P.
Dear Matthias,
>
I hope you write this code just to test the default parameter.
It wont be possible to run this code now also because none of the
pointers point to a valid memory.
Thanks and regards,
Amal P.
Hi Amal,
you are right. The code was just for demonstration. Thank you for
your accurate answer. My program works now. Btw: Do you know why
it is not possible to give a default parameter to the template parameter?
template<typena me T=int...
would look nice for me.
Matthias
On Jun 14, 7:45 pm, Matthias Pfeifer <pfe...@web.dew rote:
Dear Matthias,
I hope you write this code just to test the default parameter.
It wont be possible to run this code now also because none of the
pointers point to a valid memory.
Thanks and regards,
Amal P.
Hi Amal,
you are right. The code was just for demonstration. Thank you for
your accurate answer. My program works now. Btw: Do you know why
it is not possible to give a default parameter to the template parameter?
template<typena me T=int...
would look nice for me.
Matthias
Dear Matthias,
As you know template is a mechanism which we can use for easiness
to support different datatype, if you always want it as an int, why
you still use a template?
You should not give like that because it does not worth. If always
you are giving an int there is there any use for using a template
there?
I am sorry if i have mistaken your question.
Thanks and regards,
Amal P.
On 14 Jun, 09:20, Matthias Pfeifer <pfe...@web.dew rote:
#include <list>
using namespace std;
template<typena me T>
int* f(const int*,
const int*,
const int*,
list<pair<int, T =list<pair<int, int () );
int main (int argc, char* argv)
either
int main(int argc, char* argv[])
or
int main()
{
int* c, t, i;
int* result = f(c, t, i);
c is a pointer to int but both t and i are just ints.
also
int* c, *t, *i;
int* result = f<int>(c, t, i);
will work but but only for int
int* result = f<char>(c, t, i);
will not, since you can not convert
pair<int,charto pair<int, int>
one way would be to provide template
version
template<typena me T>
int* f(const int*,
const int*,
const int*,
list<pair<int, T = list<pair<int, T () );
and a non template version for int
int* f(const int*,
const int*,
const int*,
list<pair<int, int = list<pair<int, int () );
and then call them as
int* result = f(c, t, i); // calls int version
int* result1 = f<char>(c, t, i); // calls template version
your compiler might allow it, but main should
return a value
regards
DS
On 14 Jun, 12:49, dasjotre <dasjo...@googl email.comwrote:
your compiler might allow it, but main should
return a value
I meant, your compiler might allow you to
omit return statement, but all functions
declared as returning anything but void
must have a return statement on all
possible execution paths.
DS
On 14 Jun, 12:53, dasjotre <dasjo...@googl email.comwrote:
On 14 Jun, 12:49, dasjotre <dasjo...@googl email.comwrote:
your compiler might allow it, but main should
return a value
Your compiler must allow the omission of the return statement it in
the specific case of main.
I meant, your compiler might allow you to
omit return statement, but all functions
declared as returning anything but void
must have a return statement on all
possible execution paths.
There is an explicit exclusion for main(). If you reach the end of the
function and there is no return statement, the compiler assumes return
0;
Gavin Deane
dasjotre <da******@googl email.comwrote:
On 14 Jun, 12:49, dasjotre <dasjo...@googl email.comwrote:
>your compiler might allow it, but main should return a value
I meant, your compiler might allow you to
omit return statement, but all functions
declared as returning anything but void
must have a return statement on all
possible execution paths.
main() is special, in that the Standard explicitly allows the return
statement to be omitted, with the result that it will implicitly return
0 to the environment.
--
Marcus Kwok
Replace 'invalid' with 'net' to reply
Matthias Pfeifer wrote:
>Dear Matthias,
I hope you write this code just to test the default parameter. It wont be possible to run this code now also because none of the pointers point to a valid memory.
Thanks and regards, Amal P.
Hi Amal,
you are right. The code was just for demonstration. Thank you for
your accurate answer. My program works now. Btw: Do you know why
it is not possible to give a default parameter to the template parameter?
template<typena me T=int...
would look nice for me.
Matthias
The committee agrees with you and the next C++ revision will allow that
;). For now, you can use an overload to surcome the need to specify the
template argument:
int *f(const int* a, const int* b, const int* c)
{
return f(a,b,c,list<pa ir<int,int());
}
- Sylvester This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Penn Markham |
last post by:
Hello all,
I am writing a script where I need to use the system() function to call
htpasswd. I can do this just fine on the command line...works great
(see attached file, test.php). When my webserver runs that part of the
script (see attached file, snippet.php), though, it doesn't go through.
I don't get an error message or anything...it just returns a "1"
(whereas it should return a "0") as far as I can tell. I have read the
PHP...
|
by: Schwarzbauer Günter |
last post by:
Hello,
Does the C++ standard allow default parameters when defining a typedef for a
function type, e.g.
typedef void (*TYPE_Report)(const char* message, const char* details = 0);
This was accepted by MS Visual C++ 6.0, but is rejected in Visual Studio
..NET 2003.
I assume that this change might be because Visual Studio .NET is more C++
|
by: Razvan |
last post by:
Hi!
What is the purpose of such a function ?
int function(void)
|
by: hugheslin |
last post by:
Hi,
Please consider the following classes:
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
class Shape
{
......
......
public:
|
by: lovecreatesbea... |
last post by:
Why doesn't line# 21 create an object of type `C' class? I think the
default construction function invocation `C()' creates a temporary
nameless object, and `o1' will be built with the copy construction
function of the same class from this temporary object. With g++ (GCC)
3.4.2 (mingw-special), line 21 doesn't create `o1' as type of `C'
class. No default and copy constructions are called for this line. I
don't understand this.
For line...
| |
by: arne |
last post by:
Hi all,
imagine I call a function, but omit one of the parameters, like:
foo.c:
void foo( int a, int b ) {
/* do something with a and b */
return;
}
|
by: borophyll |
last post by:
I don't understand the difference between these two declarations
int foo(char a, char b)
{
...
}
int foo(a, b)
char a, b;
{
|
by: William Xu |
last post by:
Compiling:
template <class T = int>
T foo(const T& t)
{}
int main(int argc, char *argv)
{}
gcc complains:
|
by: Angus |
last post by:
Hello
I am writing a library which will write data to a user defined callback
function. The function the user of my library will supply is:
int (*callbackfunction)(const char*);
In my libary do I create a function where user passes this callback
function? How would I define the function?
|
by: vaib |
last post by:
hi all ,
It really seems that C never ceases to amaze . All this time
i've been doing C and i thought i was quite adept at it but i was
wrong . So without wasting any more time , here's the confusion .
I read in K&R that ANSI introduced the concept of function
prototyping in C and it was missing there initially ( it borrowed the
concept from C++ ) _but_ it did it make it compulsory to actually
include the function declaration in the...
|
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.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
| |
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 captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
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 instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
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 into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
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
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |