Great points. I forgot all about the destructor calls (when appropriate) and the non-binding nature of shrink_to_fit(). Just goes to show how memory management is pretty complicated.
Thanks...
Type: Posts; User: john.c
Great points. I forgot all about the destructor calls (when appropriate) and the non-binding nature of shrink_to_fit(). Just goes to show how memory management is pretty complicated.
Thanks...
The linker knows nothing about .h files.
The .c files are turned into .o (object) files.
The linker only deals with object files (and libraries of those).
The object files contain missing...
If you stored a million ints in a vector and then cleared it, it would be pretty arbitrary for the system to "deallocate" the memory since, as far as it knows, you may be about to fill it up again...
Exactly. There's the shrink_to_fit() method for actually returning memory back to the allocator (although it probably won't return it back to the operating system, since that's pretty much pointless).
The linker doesn't see .h files. :)
No it doesn't. That was my point. :)
Although I could've made it better by printing the capacity after the clear().
It probably just sets the size member to 0. Try this. It prints 3 for me, even though the vector was "cleared".
#include <iostream>
#include <vector>
int main() {
std::vector<int> v;
...
The program is badly structured.
Your "readline" routine should just, you know, read a line.
Then you can pass it to another function to do whatever it is you are trying to do (which I can't quite...
buffer[i] makes no sense here.
In fact, i itself makes no sense.
What are you trying to do here?
And, technically, invalid_characters should be const. (And spelled consistently!)
IMO, it would be pretty pointless to constantly check for NULL pointers and return some kind of code to the caller in every function that receives a pointer. The caller can ensure his inputs are not...
The compiler acts as if it redefines the variable every loop iteration, but it doesn't necessarily do it that way. At a high enough optimization level, it will probably notice that the entire loop...
I'm wondering if he was supposed to use the "boardGame" class in making the new class. I don't think inheritance would be correct, but maybe something like:
class tdBoard {
boardGame bg[3];...
Yes, they are all the same. The point is that you can pass the exact same array to all of them. The last version is just explicitly saying what is actually happening. The other two are in a sense...
Do you understand that these all say essentially the same thing?
void f(char matrix3d [10][20][30]);
void g(char matrix3d [ ][20][30]);
void h(char (*matrix3d) [20][30]);
When you...
head is a pointer variable that initially holds the address of the current first node, which will be NULL (basically zero) if the list is empty.
The newly created node's next pointer is set to...
I think this is what you are trying to do.
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
#include <string.h>
#define EXTEND_SIZE 256
If you're still having problems, post a complete program that I can run.
Also post the input.
This code is pretty senseless, actually.
Why is tdBoard derived from boardGame?
It's not using any of it's functionality or data at all!
You could delete 150+ lines and the program would be...
Oh, you're right. Except that the way we would usually handle it is by adding an extra space (just a space, not a newline) in front of the format of your other scanf.
int len = 0;
...
You shouldn't have the newline character in that scanf format. It should just be:
scanf("%d", &len);
I'm not sure what you're getting at. Both of those seems to "work".
However, if you mean to only allow decimal input for the integer then it's better to use %d instead of %i since %i accepts...
Thanks man. You didn't do anything wrong at all. (I really was cranky, complete with headache!)
The basic meaning of + is not an overload and they are definitely intrinsic to the compiler. They are pretty much just single assembly code instructions since the basic types correspond generally to...
This works for me (in C++14 so that the binary literals are legal) :
#include <iostream>
#include <bitset>
using State = std::bitset<4>;
struct Person {
@Zeus, perhaps if you don't know anything about a topic you can just shut the f up? He can use google himself.
At any rate, in C "generic data structure" can mean a couple of different things. It...