Jump to content

  • Log In with Google      Sign In   
  • Create Account

SiCrane

Member Since 09 Dec 1999
Online Last Active Today, 12:23 PM

#5181390 Why using std::string when you can create it yourself...

Posted by SiCrane on 18 September 2014 - 04:34 PM

Or a single template version that does all those variations based on policy classes.


#5180339 comdat folding

Posted by SiCrane on 14 September 2014 - 05:31 PM

The structs don't necessarily need to be the same size. __thiscall functions take the object argument by pointer. However, both functions are doing the same things to the same offsets into the pointer.




#5179316 Why does std::aligned_storage work only with POD?

Posted by SiCrane on 10 September 2014 - 07:40 AM

You're misreading things. That link says std::aligned_storage<>::type is POD, it doesn't say anything about any restrictions on the type you use sizeof on to get the size. 




#5174202 list index out of Range

Posted by SiCrane on 16 August 2014 - 07:48 PM

os.path is the name of a Python module. exists is the name of a function in that module. from os.path import exists says load this python module and put an alias to the exists() function into the current scope. In other words it lets you call the exists() function with exists() rather than saying os.path.exists().


#5174177 list index out of Range

Posted by SiCrane on 16 August 2014 - 05:38 PM

You passed only one argument to your script, "Ex1.txt", so argv only has length 2. Since list indices start at 0, that means argv[2] is out of bounds.




#5170787 Python IDE

Posted by SiCrane on 31 July 2014 - 09:48 PM

At work most of us use PyCharm. Those that don't tend to use vim.




#5169798 C++ std::vector vs raw array for short arrays

Posted by SiCrane on 28 July 2014 - 10:29 AM

Why exactly can't you brace-initialize this array? That isn't a C++11 only thing.

It is when your array is a member variable and you're trying to initialize it in a constructor.


#5169611 An array with multiple data types

Posted by SiCrane on 27 July 2014 - 04:05 PM

You might want to try boost::variant.




#5167072 Win32 BOOL and bool ?

Posted by SiCrane on 15 July 2014 - 08:33 PM

I actually had to double-check that info on MSDN, I thought you were trolling. But you're not. And that frightens me to death.

When it comes to the Windows API, you don't need to make stuff up. For that matter I couldn't make some of this stuff up if I tried. Another true but unbelievable detail about BOOL: there's not just one typedef or two typedefs for boolean types in the API, but three of them (that I know about): BOOL, BOOLEAN and VARIANT_BOOL. They are respectively, 4 bytes, 1 byte and 2 bytes. VARIANT_BOOL is especially interesting because it doesn't use non-zero for true but specifically 0xffff (-1 as a short). Also BOOL and VARIANT_BOOL are signed, and BOOLEAN is unsigned. BOOLEAN is a fun one because you can do accidental integer conversions that don't mean what you think they do. bool(my_int) means true if my_int is non-zero. BOOLEAN(my_int) means take the least significant byte (in other words 256 would look like false).


#5166901 Win32 BOOL and bool ?

Posted by SiCrane on 14 July 2014 - 09:32 PM

Note that sometimes the use of BOOL in the Windows API is a lie and is not actually a boolean. For the GetMessage() function, 0 indicates WM_QUIT, non-zero indicates a non-WM_QUIT message except for -1 which means an error. 




#5165733 c++ function pointers

Posted by SiCrane on 08 July 2014 - 11:32 PM

The easiest way is to use a typedef. Ex:  typedef int (*function_type)(int). Then function_type GiveMeFunctionPointer()


#5154357 c++ class vs struct+functions

Posted by SiCrane on 17 May 2014 - 08:52 PM

Assuming the member functions are non-virtual they'll compile into essentially identical machine code as functions that accept structs as pointer or reference arguments.




#5148473 C++ std::move() vs std::memcpy()

Posted by SiCrane on 20 April 2014 - 09:22 PM

One situation where memcpy() won't work but std::move() will is when the object's constructors and destructor handle self-registration. For example, if it registers itself as part of the root set to a garbage collector by giving the garbage collector it's address. If you just copy the the memory without updating the root set for the GC, the GC will be trying to use the old memory location for its sweeps.




#5147379 c++ oo syntax behind the scenes behavior

Posted by SiCrane on 16 April 2014 - 10:28 AM

 

where is the VMT stored, and when ?

With the memory of the class, when the class is created - usually alongside the member variables in memory.
 

I think you're confusing a pointer to the vtable and the vtable itself. An object will store a pointer to the vtable not the full table. The vtables themselves are generally stored in a read only data segment. 




#5146762 Error from/with unique_ptr trying to acces private member, error C2248

Posted by SiCrane on 13 April 2014 - 02:28 PM

A unique_ptr is movable but not copyable, which means a std::vector of unique_ptrs is also not copyable. And a class that contains a std::vector of unique_ptrs would also not be copyable with the default copy constructor or assignment operator. One option in your case is to give your Bag a copy constructor that clones all the pointed to Items. Another option is to use shared_ptrs instead of unique_ptrs.






PARTNERS