I wish to know how a function signature is validated [closed] - c++

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 10 years ago.
I currently believe it is the compiler or the return type that does this but I'm not sure I just need a clarification

A function signature is matched first by it's name, then by it's arguments. Never by it's return type. For example if you have two methods called Add one taking two int values and returning a int and one taking two string values and returning a string, and you called it passing ints it wouldn't matter what you were setting it to the int version would be called.
Where this can get you in a bit of trouble is when you try method overloading with different numeric values. the compiler will try and help you (if you call a method expecting ints but pass a short it will try and figure out what you are trying to do).

Related

Visual C++ member variables changing unexpectedly and unexplainably [closed]

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 9 years ago.
I'm initializing an instance of PhysWorld class as shown here:
At this point the member variables are as follows:
This seems correct to me.
Then this line executes:
We step into:
And at this point, the member variables look like:
Can someone please help me understand what is going on here? This is one of my first attempts in c++ so I'm guessing it's something stupid on my part.
Thanks!
You probably loose variable value on assignment:
pw = PhysWorld(...);
This statement constructs a temporary object, and then makes a call: pw.operator=(const PhysWorld&);. Check how you implement it (if you do).
Also your function setRectDef contains a serious bug: you are storing a pointer to a stack variable, which would be invalid after leaving the function scope, and accessing it later most likely ruin your stack.
Edit: how to handle tmpS.
You need to allocate your structure on heap:
b2PolygoinShapre *tmpS = new b2PolygoinShape;
tmpS->SetAsTextBox(...);
this->rect = tmpS;

How to manipulate CString's content [closed]

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 10 years ago.
guys, I have a problem, please help me!
I have a CString variable which will receieve from Database,and the data may like this:(8)(9)(10)(11) or more.
Now I want to change every number in CString,for example, add 1,the outcome should like this:
CString Data; the contest of CString data variable should be changed.
Before: (8)(9)(10)(11)
After: (9)(10)(11)(12)
I've tried Data.GetAt(i),but it returns a const pointer and I can't change it.
I konw maybe Data.GetBuffer() can get a pointer to manipulate CString,but I don't know how to do it.
So please help me ! Thanks a lot!
Don't change in-place. Specifically in your example, when you change (9) to (10) it needs 1 extra character of buffer space. Extract all the values somehow (a std::list of int perhaps), add whatever numbers you need, and then re-assemble into a string, and write it back all at once.

Create a powerful dictionary [closed]

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 10 years ago.
I want to creat a class or something in order to store different kinds of information, like string, map, bool, int, etc.
I want to do is like: 
dictionary func(dictionary & dict){}.
And the content in the dictionary is not fixed, maybe I use func1(), and func2(), but they require different arguments.
For now, I created a class to store arguments, it has different kinds of members, is it a good way? Or I need to find a good solution? Thanks
You would be best served by leveraging the existing std::undordered_map hashtable/map implementation perhaps in combination with boost.any if you want to mix key or value types.

Haskell function which takes a list and return tuples [closed]

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 12 years ago.
I have ordederd to make a function, which takes a list ex [3,4,6,1,29] and returns a list of tuples [(3,4),(4,6),(6,1),(1,29)]
This is a very easy question, it's really hard to help without defeating the purpose...
If you are allowed to use predifined functions, there is already one which can do almost all work for you (if you don't know which one, try finding it with http://www.haskell.org/hoogle/ ). Take a step back and think about the easier question how to produce a list [(3,3),(4,4),(6,6),(1,1),(29,29)].
If you can't use predefined functions, then recursion is your friend: What do you need to do for an empty list? What for a list with one element? With two elements?
Without any own effort I can't give more hints. If you're stuck, extend your question and show what you already got, and we'll try to help.

Possible compilation errors in C++ [closed]

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 12 years ago.
In C++, what kind of compilation errors might I run into while using function overloading, and when might these occur?
This website has a couple listed, though I think your question will probably get closed as not a real question:
http://net.pku.edu.cn/~course/cs101/resource/CppHowToProgram/5e/html/ch06lev1sec17.html
Creating overloaded functions with identical parameter lists and
different return types is a
compilation error.
A function with default arguments omitted might be called identically to
another overloaded function; this is a
compilation error. For example, having
in a program both a function that
explicitly takes no arguments and a
function of the same name that
contains all default arguments results
in a compilation error when an attempt
is made to use that function name in a
call passing no arguments. The
compiler does not know which version
of the function to choose.