Can you pass a standard c# enum as a parameter?
For example:
enum e1
{
//...
}
enum e2
{
//...
}
public void test()
{
myFunc( e1 );
myFunc( e2 );
}
public void myFunc( Enum e )
{
// Iterate through all the values in e
}
By doing this I hope to retrieve all the names within any given enum. What would the Iterat...
As a follow on from this question.
How can I call a function and pass in an Enum?
For example I have the following code:
enum e1
{
//...
}
public void test()
{
myFunc( e1 );
}
public void myFunc( Enum e )
{
var names = Enum.GetNames(e.GetType());
foreach (var name in names)
{
// do something!
}
}
...
I happened to be making some changes to a WordPress blog and noticed that they use parse_str (http://php.net/parse_str) for parsing and setting their optional parameters to a function.
I'm wondering if there is an advantage to this over sending an array?
Examples:
With array:
$blahOptions = array(
'option_1' => true,
);
BlahArra...
I need to be able to pass a typename as a parameter:
int X = FileRead(file, 9, char);
The concept is for FileRead(std::fstream, int pos, ???) to read pos*sizeof(whatever the type is) to get the desired position. I tried templates:
template<typename T>
T FileRead(std::fstream file, int pos, T type)
{
T data;
file.read(reinter...
So, many times we have a function that accepts an IEnumerable or ICollection as a parameter. In cases where we have single items, but no collection to hold them, we must create a collection before passing them to the function, like:
T o1, o2, o3;
Foo(new T[] { o1, o2, o3 });
I've always created an array or a list, like I've done in th...
I'm trying to write a function to swap 2 elements in a 2D array:
void swap(int surface[][], int x1, int y1, int x2, int y2) {
int temp = surface[x1][y1];
surface[x1][y1] = surface[x2][y2];
surface[x2][y2] = temp;
}
however when I try to compile it (gcc), I get this error message:
Sim_Annealing.c: In function `swap':
Sim_...
I need to log all the function parameters in a dozen functions.
Is there a way to pro grammatically determine all the parameters and their values (or at least their .ToString() value)? Perhaps via reflection?
...
Is it possible to create a PHP function that takes a variable number of parameters all of them by reference?
It doesn't help me a function that receives by reference an array of values nor a function that takes its arguments wrapped in an object because I'm working on function composition and argument binding.
Don't think about call-tim...
In Java you can access variables in a class by using the keyword this, so you don't have to figure out a new name for the parameters in a function.
Java snippet:
private int x;
public int setX(int x) {
this.x = x;
}
Is there something similar in C++? If not, what the best practice is for naming function parameters?
...
I have the following problem: I have a function which takes a List[Double] as parameter, performs some arithmetic operations on the elements of the list and than return the result. I would like the function also to accept List[Int]. Here is an example:
def f(l: List[Double]) = {
var s = 0.0
for (i <- l)
s += i
s
}
...
I have a function that takes a const D3DVECTOR3 *pos, but I have no reason to declare this beforehand. The most logical solution to me was using new:
Function(
//other parameters,
new D3DXVECTOR3(x, y, 0));
but I don't know how I would go about deleting it, beign intitialized in a function. My next thought was to use the & o...
Something like this (yes, this doesn't deal with some edge cases - that's not the point):
int CountDigits(int num) {
int count = 1;
while (num >= 10) {
count++;
num /= 10;
}
return count;
}
What's your opinion about this? That is, using function arguments as local variables.
Both are placed on the s...
I need a function which takes an arbitrary number of arguments (All of the same type), does something whith them and afterwards gives a result back. A list of arguments is impracticable in my specific case.
As I looked through the haskell libs, there is the function printf from module Text.Printf, which uses a similar trick. Poorly I co...
hello ,
I have recently started working on OpenCV using c++.I am having a problem with the following code.
#include "cv.h"
#include "highgui.h"
int g_slider_position = 0;
CvCapture* g_capture = NULL;
void onTrackbarSlide(int pos) {
cvSetCaptureProperty(
g_capture,
CV_CAP_PROP_POS_FRAMES,
pos
);
}
int main( int argc, ch...