Possible compilation errors in C++ [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 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.

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;

Implementation of vector of integers with overloaded operators, fails to run properly [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 have huge problems with making this code work properly.
http://pastebin.com/Mi6gj188
There's an output from example program on the bottom. It simply crashes and doesn't deliver proper results too. It seems that none of the overloaded operators work as it should
You didn't write a copy constructor, or use RAII. As a result, every time your vector object is copied (and it is, a lot, because you make no use of references!!) your internal data pointer is copied, sharing it amongst multiple objects (each of which will attempt to delete it on destruction) causing a horrible bug.
Your book tells you about the rule of three, which you should now go ahead and work on following.

remove or replace duplicated C++ code in one function on Linux [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 am working on C++ on Linux.
I need to remove some duplicated code in two functions.
One function is for computing and another one is for logging.
There are some code that are duplicated in logging(), which is much longer than computing().
The duplicated code is distributed in logging() separately, which means that they are not just copy and paste from computing().
I need to figure out the duplicated part line by line, remove them and then replace the necessary results by passing them as parameters from computing() to logging.
Are there some efficient ways to handle this ?
Look at the functions side by side, identify common blocks of code, then factor these common blocks out into separate methods/functions.
It might not be worth merging them. If you really have to, though, perhaps one common function with an extra bool do_logging parameter.

I wish to know how a function signature is validated [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 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).

Using const on local variables [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 11 years ago.
Similar to this question, what are the pro/cons to using const local variables like in this answer?
Personally, I like to use const for any declared object (I'm not sure the word "variable" applies) unless I'm actually going to modify it. It documents to the reader that the value of the object is always going to be whatever it was initialized to, which can make the code easier to follow and analyze.
(It can also help the compiler in some cases, but most compilers, when invoked in optimizing mode, are smart enough to notice that the object is never modified. And if you invoke the compiler in non-optimizing mode, you're telling it that you don't care much about performance.)
In fact, if I were going to design my own language, all declared objects would be const (read-only) by default unless you explicitly mark them as modifiable.