function with args is calling another function with same args [duplicate] - c++

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?

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++ array length function give me a different result than main function [duplicate]

This question already has answers here:
size of array passed to C++ function? [duplicate]
(7 answers)
determine size of array if passed to function
(10 answers)
Sizeof in function [duplicate]
(1 answer)
Closed 6 months ago.
#include<iostream>
#include <string>
using namespace std;
void show_length(int array1[]){
int length=sizeof(array1)/sizeof(array1[0]);
cout<<"Length inside function = "<<length<<"\n";
}
int main(){
int array1[6]={3,6,4,2,1,4};
int length=sizeof(array1)/sizeof(array1[0]);
cout<<"Length inside main = "<<length<<"\n";
show_length(array1);
system("pause");
}
i recive 6 as an answer in the main (which is the right answer) but 2 in the separate function, why this happens?

How can we send a multidimensional array to a function? [duplicate]

This question already has answers here:
Passing a 2D array to a C++ function
(17 answers)
How to pass a 3D array as a parameter to function C++? Also Do global variables need to be passed into functions?
(3 answers)
Passing 3D array as parameter to a function in C
(1 answer)
Closed 8 months ago.
We can send a simple array with no information about its size , but in matrixes we have to define number of raw , how about in multidimension array (more than 2 dimension) ?
void f1( int a[][][3]);
is it true ? or I have to define second dimension ?

How to Call function with default parameter? [duplicate]

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);

Different ways of declaring a function in C++ [duplicate]

This question already has answers here:
How does this template magic determine array parameter size?
(3 answers)
Can someone explain this template code that gives me the size of an array? [duplicate]
(4 answers)
How does this "size of array" template function work? [duplicate]
(1 answer)
Closed 2 years ago.
I have come across the following code snippet in C++ and I have no idea what it means;
#include <iostream>
char (&some_function(int (&some_input)));
int main ()
{
// main code here
return 0;
}
How is some_function a function? what kind of syntax is this? where is the body?
I'm sure this is only a C++ syntax as it doesn't compile in C.
Edit:
Actual code with above style:
template <typename T, size_t N>
char (&ArraySizeHelper(T (&array)[N]))[N];
#define arraysize(array) (sizeof(ArraySizeHelper(array)))