Jump to content

  • Log In with Google      Sign In   
  • Create Account

SiCrane

Member Since 09 Dec 1999
Offline Last Active Today, 04:08 PM
*****

#5070995 Why only the = operator is not inherited?

Posted by SiCrane on Yesterday, 07:19 PM

I wouldn't go so far as to say that a base class implementing the copy/move operations or the destructor is a strong indication that a derived class should. The compiler generated defaults will call the base class versions. If your base class requires derived classes to do anything more than that then that's a pretty good indication that the base class versions are implemented incorrectly.




#5070970 Why only the = operator is not inherited?

Posted by SiCrane on Yesterday, 04:44 PM

It is inherited. However, unlike other operators, a derived class will generate an implicitly defined assignment operator that will hide the base class version. However, with explicit qualification the derived class can access the base class version if it wants to.




#5070228 POD structs and the Assignment operator

Posted by SiCrane on 16 June 2013 - 01:43 PM

std::shared_ptr works by creating a reference count object on the heap and storing the number of live shared_ptrs in that object. However, COM objects already do reference counting through AddRef() and Release(), so there's no need to create this extra object. Hence, it's generally better to use a smart pointer that knows about the AddRef() and Release() functions and use that. One example is the CComPtr class in ATL, though there are other smart pointers designed to work with COM out there.


#5070154 POD structs and the Assignment operator

Posted by SiCrane on 16 June 2013 - 08:47 AM

First note: your Player class isn't POD. In order to be POD all the member variables also have to be POD and your Player class contains a std::string object. As for overloading the assignment operator, if you don't define an assignment operator the compiler will define an assignment operator that does a member by member assignment. If you want your assignment operator to do something different than calling the assignment operator for each of the member variables then you create your own assignment operator implementation.




#5070055 C++ vector of class objects referencing external class

Posted by SiCrane on 15 June 2013 - 04:59 PM

Every time you use push_back() to put something in a vector, the vector makes a copy of the object you pass it. If you pass push_back() a temporary object, the vector will make a copy of the temporary and then the compiler will destroy the temporary. It's also possible that they way you're reading from the vector is also generating extra temporary objects.

 

How are you tracking your CUnit destruction? It's entirely possible that you aren't seeing matching construction and destruction counts because you aren't tracking copy constructor calls.




#5069495 Using nonvirtual inheritance for informal 'interfaces'?

Posted by SiCrane on 13 June 2013 - 12:44 PM

I don't really see the point. If you try calling a member function on a class that doesn't support it you'll get a compiler error even without any tricky base class usage.




#5069211 Function pointer as unique [system] id

Posted by SiCrane on 12 June 2013 - 01:57 PM

If you create a pointer to a member function for a virtual function what you'll get is a member function pointer that always calls the most derived function implementation for that virtual function.




#5068430 Debugging

Posted by SiCrane on 09 June 2013 - 09:46 AM

One way to debug heap corruption on Windows is to use Application Verifier, in particular the page heap functionality.


#5068226 store values from string in an array

Posted by SiCrane on 08 June 2013 - 07:27 AM

Rather than first creating a string and then parsing the contents to create an array, it would probably make more sense to create the array first and generate the string from the array (for example with String.Join()).


#5067378 Challenge #2: What tools can you not live without?

Posted by SiCrane on 04 June 2013 - 10:18 AM

On Windows, I constantly use cygwin, which gives you the common *nix applications for Windows. This includes text tools like grep and tail as well as development tools like gcc, clang, make, git, svn, and so on.


#5066578 *Want* Multiple Base Objects

Posted by SiCrane on 31 May 2013 - 08:13 PM

It's possible, but a really bad idea. One way:
template <int i> struct BaseHelper : FBO2D {
  // add appropriate forwarding functions
};

struct FBOCube : BaseHelper<0>, BaseHelper<1>, BaseHelper<2>, BaseHelper<3>, BaseHelper<4>, BaseHelper<5> {
};



#5065895 What am I missing here?

Posted by SiCrane on 29 May 2013 - 12:44 PM

Are you sure that you're calling init() on a valid object?

As a side note, you're passing std::vector objects around by value which can be rather inefficient; you may want to switch to pass by reference instead.


#5065371 std::bind and function

Posted by SiCrane on 27 May 2013 - 06:20 PM

You can form a valid C++ statement by placing a semi-colon after an expression. A string literal is a expression.


#5063980 expected template ambiguity

Posted by SiCrane on 22 May 2013 - 05:44 PM

You probably want to read this article.


#5063345 Convert std::string to WCHAR ?

Posted by SiCrane on 20 May 2013 - 05:27 PM

You might be able to use mbstowcs() to do so. If you gave more information, like what platform you are using then a more confident answer could be given.




PARTNERS