Quantcast
Channel: User BoP - Stack Overflow
Browsing latest articles
Browse All 169 View Live

Answer by BoP for How do I revert renaming "unsigned long" to "unsigned long...

How could I revert this? I have already closed and re-opened theproject.That's the second mistake. :-(If you recognize an error in a find-replace, just choose Edit->Undo, and everything is reverted....

View Article



Answer by BoP for std::move and lifetime of temporary objects

In std::move(Foo()); the Foo object is bound to the parameter of the move-function, not to baz.And when the function returns, the temporary is destroyed.

View Article

Answer by BoP for Auto Registering Factory Stops Working In Source Files

The earlier question talks about static libraries. That's important.If you have a source file in a library, the linker will pull it in only if something else refers to the symbols in that file....

View Article

Answer by BoP for Why isn't this printing 5 items at a time?

We assume that the program read some input earlier, like names. We also assume that this input was terminated by pressing Enter.Then this Enter is still in the input buffer, just waiting for ignore()to...

View Article

Answer by BoP for Is the constructor or the code the problem?

You have a conflict between the class time, and the function time from the standard library.Heretime Time[4];the compiler expects a parameter for the function call.This is one reason for avoiding using...

View Article


Answer by BoP for Memory organisation with inheritence and pointers

For members of a struct or class, the only rule is that later members will have a higher address. That's it! There is no rule about how much higher the address must be (except to avoid overlap). The...

View Article

Answer by BoP for Zip Class in C++ (Internal Object Lifetime)

explicit Zip(const Ts&... objs) : m_data(objs...) { }The lifetime extension works for a direct binding only, the temporary is bound to the objs parameter.The lifetime extension is not transferred...

View Article

Answer by BoP for Forward declaring a specific template instance

The first declaration says that MyClass is a class. The second one says that it is not, it is an alias. Those are different.The problem is not realated to templates. You get the same error for class A;...

View Article


Answer by BoP for I don't want to use pointers but compiler is saying...

Redefining an name halfway through the function is not a great idea.const int size = 100; // Here size is an intint code[size]; // ok, fineint size[size]; // now size is an array?int quantity[size]; //...

View Article


Answer by BoP for When can the standard library functions throw exceptions?

Sometimes you have to read between the lines.The string operator[] has a precondition that the index must be valid. cppreference says:If pos > size(), the behavior is undefined.Undefined behavior...

View Article

Answer by BoP for Why do algorithms use iterator_traits::value_type instead...

A pointer is a valid iterator type (into an array, for example), but has no value_type member. However, iterator_traits still works for that pointer type.

View Article

Answer by BoP for stringstream good() return value with char vs. string

If you check the other status functions, I'm sure the difference is in ss.eof().Reading a char only ever tries to read one character, and doesn't notice if there is anything more in the stream.

View Article

Answer by BoP for Array variables didn't get allocated in a data section when...

The first part specifies attributes for variables.The second part specifies attributes for types, which doesn't include a __section__ option.So, apparently you can specify that a specific variable...

View Article


Answer by BoP for error when compiling c flie with cblas.h, getting error...

The complex float type in the message hints at I coming from the <complex.h> header.https://en.cppreference.com/w/c/numeric/complex/IYet another reason for not using all uppercase in identifiers...

View Article

Answer by BoP for Overloading operator delete with additional argument of...

Where does argument std::size_t sz get assigned value?The compiler does that. The expression delete var; has two parts - first the destructor for P (if any) is called, and then operator delete is...

View Article


Answer by BoP for C++17 Compiler is not visible/detected in Visual Studio...

Microsoft didn't dare to change the macro after being at C++98 for 20 years! So they added a special option to enable an updated...

View Article

Answer by BoP for How two different values can store in one memory space in C...

&q is the address of the pointer variable q.&q+1 is the address of the first byte afterq.&p is the address of the pointer variable p.if (&p == &q+1) tests if p is stored in the...

View Article


Answer by BoP for Why I get the error: "incomplete type is not allowed" in c++?

(Now that the question is reopened, lets make an answer from my comment)The code first declares a struct with no name, and a typedef alias for that struct:typedef struct { int SqBiTNode[MAX_SIZE]; int...

View Article

Answer by BoP for a function declaration without a prototype is deprecated in...

The link talks about "function declaration without a prototype", which are these link *search_link() , *pred_link();Once upon a time you could leave () empty, and the compiler would have to kind of...

View Article

Answer by BoP for rdbuf in basic_ios and basic_fstream

You can have two functions with the same signature, if they are in different scopes. A derived class is like an inner scope compared to its base classes.The new function will hide similar named things...

View Article

Answer by BoP for Why does hash table printing function not work?

The loop in main inserts a pointer to p1 each time. That makes all the hash entries be the same (and hold a dangling pointer).You should instead allocate a new struct for each entry.

View Article


Answer by BoP for How vtable and vptr is working when virtual method is...

this -> print(); is just print() and uses the vtable to call the member of the actual type, as the function is virtual. That's what virtual functions are used for.Base::print(); just calls the...

View Article


Answer by BoP for C++ Error calling a function from unnamed namespace

Every time you include the header, you get a new unnamed namespace with a different secret name.The only way to make it "work" is to only include it once, and only use the objects in that one source...

View Article

Answer by BoP for A question about the argument types to the comp predicate...

but why is Type1 not allowed? Is it only due to optimization, takingcues from the precondition that Type1 is allowed if a move isequivalent to copy? Or is there more to it than that?It is the same...

View Article

Answer by BoP for Why is heterogenous std::*map lookup opt-in in C++?

The map template has a default comparisontemplate< class Key, class T, class Compare = std::less<Key>, class Allocator = std::allocator<std::pair<const Key, T> >> class...

View Article


Answer by BoP for why use template in year_month class?

You have two very similar overloads for operator+, originally without the templatetemplate <int = 0>constexpr year_month operator+(const year_month& _Left, const months& _Right)...

View Article

Answer by BoP for What does the “class” keyword mean within a member...

It's about the lines that start with FORCEINLINE class. Is a new classbeing declared here or what exactly does it mean?In some other languages we have the term "forward declaration" when you just...

View Article

Answer by BoP for having issue with cin.getline() when working with char data...

If I enter 12345 to arr2, why will the program skip thecin.getline(arr3,6,'#') and just finish?The line cin.getline(arr2,5,'#'); says that arr2 is a pointer to an array of 5 chars. That size includes...

View Article

Answer by BoP for Lock efficiency problem in high contention environment?

It is not about being "more efficient", it is about being less bad. If you have 100s of threads spinning on the same lock, they will waste lots of CPU time that could be better used by the thread...

View Article



Answer by BoP for Error finding determinant of a C++ 2 dimensional array

Even ifif(m == 2){ return arr[0][0]*arr[1][1] - arr[0][1]*arr[1][0];returns a value and ends the function call, the rest of the function must still compile.The problem is that Determinant<m-1>...

View Article

Comment by BoP on assigning a value of 0 instead of what is written in the code

The compiler might very well skip assigning 1 to d, when d is already set to 1 two lines above. If the memset then goes out of bounds for the array...

View Article

Comment by BoP on Regular expression equivalent in C++

Also, if your raw string is supposed to contain (, ", and ), you might want do use extra string delimiters

View Article

Comment by BoP on GCC | My least possible C code size if 15KB and i can't...

The example command lines look like they are using -0s (digit zero) when the proper optimization option is -Os (letter O).

View Article


Comment by BoP on char array and char pointer c++

The difference in output for strings comes from an overload of operator<< that treats const char* as pointing to a string. There is no such special overload for int*.

View Article

Comment by BoP on How I can cout vector

You can write a print function with the two-line for-loop, and then you can do print(x) just like in python. And if your compiler happens to support C++23, you can even use std::print instead.

View Article

Comment by BoP on Incompatible pointer types when declaring a struct

The struct doesn't have a name, so struct numbers doesn't name this struct. And the typedef numbers isn't visible until the next line.

View Article


Comment by BoP on how to create vector from 7 integers

You should have a >> for each input variable, not a comma.

View Article


Comment by BoP on Why is the value of z for the given code snippet of C++...

If it is any consolation, you will not have to write (++x) + (x=10) in real code. Never happens! So the fact that it doesn't work is not important.

View Article

Comment by BoP on How to implement classes in C++ for Bank Management System

And having worked for a bank, I can attest that "initial balance" is unfortunately always zero on a new account. You really need a deposit to get a positive balance. And like paddy says set_balance is...

View Article

Comment by BoP on Is my understanding of std::map and std::unordered_map...

@ChristianStieber - The committee surely had a possible implementation in mind when specifying the requirements. They didn't want to spell that out though, on the odd chance that a better way happens...

View Article

Comment by BoP on compile files failed when .h and .cpp in different folders

As an aside, the file names in #include are formally not string literals, so don't need escaped backslash characters. And you can use forward slashes / anyway, even on WIndows.

View Article


Comment by BoP on error "invalid or corrupt file cannot read at 0xE4F7" when...

Also, if you have a pawn.cpp file for your program, the C++ compiler will create a pawn.obj file with the resulting binary "object code". Possible source of confusion!

View Article

Comment by BoP on Why did I get "incompatible pointer to integer ..."warning?

*RawAudio is a char, that cannot hold a pointer. Did you mean RawAudio without the star?

View Article


Comment by BoP on x86 assembly c++ string array to int array convertion

Suppose the standard library uses a C++ template to implement atoilink. Then calling that from assembly looks kind of silly.

View Article

Comment by BoP on the linker does not allow the program with code 1 to...

The compiler (or linker, really) claims that it cannot find where ~Organism is implemented. Neither can I.

View Article

Browsing latest articles
Browse All 169 View Live




Latest Images