How to Call function with default parameter? [duplicate] - c++

This question already has answers here:
Skip some arguments in a C++ function?
(4 answers)
how to skip Default Arguments C++?
(4 answers)
C++ Skipping first default parameter in call
(4 answers)
Closed 2 years ago.
I have a function define in header file as this:
int myfunction(VpTR*& viewporttable, wchar* vpname=L"*Active", OpenMode f=fR);
how i can call this function but ignore second argument?
I tried calling it with the following code but an error message appeared: expected an expression
myfunction(myviewporttable,, fR);
can i omit this argument but it still understands L "* Active" as the called value?

The syntax doesn't allow to omit parameter values at arbitrary positions, only those at the very end of the list.
You have to overload 2 versions:
int myfunction(VpTR*& viewporttable, OpenMode f=fR) {
return myfunction(viewporttable,L"*Active",L"*Active",f);
}
int myfunction(VpTR*& viewporttable, wchar* vpname=L"*Active", OpenMode f=fR);
Then you can call
myfunction(myviewporttable, fR);

Related

no matching function for call to ‘make_shared<unsigned char [x]>()’ [duplicate]

This question already has answers here:
Can you allocate an array with something equivalent to make_shared?
(4 answers)
shared_ptr to an array : should it be used?
(2 answers)
Closed 8 days ago.
I am using a template called Temp, and I have a shared pointer defined like this
std::shared_ptr<Temp[]> ptr;
I use make shared like this
this->ptr = std::make_shared<Temp[x]>();
Where x is int value for the number of elements I want to store.
int x = this->GetSize();
I get this error:
error: no matching function for call to
‘make_shared<unsigned char [x]>()’

(C++) Expression must have a constant value [duplicate]

This question already has answers here:
Using const int as array size
(5 answers)
Closed 4 years ago.
Visual Studio is for some weird reason showing me this error and keep saying that count is not const int while trying to initialised array. Check image.
Error: expression must have a constant value
This is function call at main:
std::string fileName("shows.tv");
const int COUNT = 10;
Episode** episodes = loadEpisodesFromFile(fileName, COUNT);
and this is function declaration at header file:
Episode** loadEpisodesFromFile(std::string, const int);
I don't get it. Variable count is already declared as const int but it's not working.
Episode* episodes[count] is not valid because count is a parameter from the function
loadEpisodesFromFile which is unknown at compiling time...
you need to use an std::vector instead
std::vector<Episode*> episodes(count);

What's going on at tolower? [duplicate]

This question already has answers here:
what is the meaning of (*(int (*)())a)()?
(3 answers)
Closed 4 years ago.
I was reading this answer: https://stackoverflow.com/a/5539302/588867
What is going on with this part: (int (*)(int))tolower in this line of code:
transform(s.begin(),s.end(),s.begin(),(int (*)(int))tolower );
If I make this function and the code works:
int myToLower(int c){
return tolower(c);
}
transform(s.begin(),s.end(),s.begin(), myToLower);
What's plain English about this part: (int (*)(int)).
You can see this answered in my answer, that's a function pointer. You can read more about them here: http://en.cppreference.com/w/cpp/language/pointer#Pointers_to_functions
Fundamentally this is a pointer to a function that takes in an int argument and returns an int.
The reason the transform works when using myToLower and not with an uncast tolower, is that in code is that the tolower function is overloaded in the std namespace by both the locale library's tolower and the ctype library's tolower. When only the function name is used as an uncast pointer no overload resolution is performed, and you'll get an error. When you cast the function pointer you're telling the compiler which overload you want.

How can i call below C++ function with size_t* in Objective c ios [duplicate]

This question already has an answer here:
Calling C++ method from Objective C
(1 answer)
Closed 6 years ago.
I want to call this function void getResult(char, size_t*) in objective c.How can i do this please help me.
It give me below error show in image.
It seems your getResult function expects to get second parameter by reference. You can't pass function result by reference. Assign it to actual variable first and then pass reference to that.
unsigned long sizeOfC = sizeof(c);
c->getResult(array1, &sizeOfC);

function with args is calling another function with same args [duplicate]

This question already has answers here:
call printf using va_list
(4 answers)
C: Passing variable number of arguments from one function to another
(5 answers)
Closed 8 years ago.
I want to develop a c function with random number of arguments:
int myfunction(char *fmt,...) {
....
}
then in my function I want to call printf() with the same input arguments of my function (the fmt and the other random arguments):
int myfunction(char *fmt,...) {
....
printf(/*What I have to put here?*/)
....
}
How I can call printf() in this case?