given the next code:    class A {       // ... };  class B : public A {       // ... };   And:   A a;    B b;     A&amp; ab = b;    ab = a;    Will be a slicing in the last line of this code? Why?
664
Someone mentioned it in the IRC as the slicing problem.
96218
I came across this code and wanted others to provide their point of view... is it good or bad ? ;)  Class ReportClass {  public string ReportName {get; set;} }   Then it was used as follows in code:  displayReport(ReportClass.ReportName = cmbReportName.SelectedValue.ToString())   That is about the simplest form example I can give you. Quetion is... why can't I find examples ? What would this be called? Is this just asking for trouble?  EDIT: I'm referring to the inplace assignment. Which I wasn't aware of until today
3226
class String {      private:         char* rep;      public:         String (const char*);         void toUpper() const; };   String :: String (const char* s) {     rep = new char [strlen(s)+1];     strcpy (rep, s); }   void String :: toUpper () const {     for (int i = 0; rep [i]; i++)     rep[i] = toupper(rep[i]); }   int main () {     const String lower ("lower");     lower.toUpper();      cout &lt;&lt; lower &lt;&lt; endl;     return 0; }
12628
Is there a benefit to using one over the other? In Python 2, they both seem to return the same results:  &gt;&gt;&gt; 6/3 2 &gt;&gt;&gt; 6//3 2
112174
There's some code in our project that looks a bit like this:  Private Sub Method1()     Call InnerMethod End Sub  Private Sub Method2()     InnerMethod End Sub  Private Sub InnerMethod()     '' stuff End Sub   What's the advantage of doing Method1 over Method2?
18453
Is it more efficient for a class to access member variables or local variables? For example, suppose you have a (callback) method whose sole responsibility is to receive data, perform calculations on it, then pass it off to other classes. Performance-wise, would it make more sense to have a list of member variables that the method populates as it receives data? Or just declare local variables each time the callback method is called?  Assume this method would be called hundreds of times a second...  In case I'm not being clear, here's some quick examples:  // use local variables class thisClass {     public:         void callback( msg&amp; msg )         {             int varA;             double varB;             std::string varC;             varA = msg.getInt();             varB = msg.getDouble();             varC = msg.getString();              // do a bunch of calculations          }  };  // use member variables class thisClass {     public:         void callback( msg&amp; msg )         {              m_varA = msg.getInt();              m_varB = msg.getDouble();              m_varC = msg.getString();               // do a bunch of calculations         }      private:         int m_varA;         double m_varB;         std::string m_varC;  };
866
In the following method definitions, what does the * and ** do for param2?  def foo(param1, *param2): def bar(param1, **param2):
72062
The question says it all really.  Am I allowed derive a class from a struct, or should I create a class that embeds my struct and defines copy constructors and an = operator to move between the two?
78567
Can someone please explain to me how to deal with equivalence relations on classes instead of sets? Is there some sort of generalisation of relations?  Thank you
22301
I just came across an interesting situation in JavaScript.  I have a class with a method that defines several objects using object-literal notation.  Inside those objects, the this pointer is being used.  From the behavior of the program, I have deduced that the this pointer is referring to the class on which the method was invoked, and not the object being created by the literal.    This seems arbitrary, though it is the way I would expect it to work.  Is this defined behavior?  Is it cross-browser safe?  Is there any reasoning underlying why it is the way it is beyond "the spec says so" (for instance, is it a consequence of some broader design decision/philosophy)?  Pared-down code example:  // inside class definition, itself an object literal, we have this function: onRender: function() {      this.menuItems = this.menuItems.concat([         {             text: 'Group by Module',             rptletdiv: this         },         {             text: 'Group by Status',             rptletdiv: this         }]);     // etc }
108429
When are objects or something else said to be "first class" in a given programming language, and why? In what do they differ from languages where they are not?  EDIT. When one says "everything is an object" (like in Python), does he indeed mean that "everything is first-class"?
28775
Is it better to initialize class member variables on declaration  private List&lt;Thing&gt; _things = new List&lt;Thing&gt;(); private int _arb = 99;   or in the default constructor?  private List&lt;Thing&gt; _things; private int _arb;  public TheClass() {   _things = new List&lt;Thing&gt;();   _arb = 99; }   Is it simply a matter of style or are there performance trade-offs, one way or the other?
106335
What does the following mean?  Class.Function(variable := 1 + 1)   What is this operator called, and what does it do?
30661
This is a question that was sparked by 's answer . Suppose I declare a class/struct like so: struct {      char A;     int B;     char C;     int D; };  Is it safe to assume that these members will be declared in exactly that order in memory, or is this a compiler dependent thing?  I'm asking because I had always assumed that the compiler can do whatever it wants with them. This leads into my next question.  If the above example causes memory alignment issues, why can the compiler not just turn that into something like this implicitly: struct {      char A;     char C;     int B;     int D; };  (I'm primarily asking about C++, but I'd be interested to hear the C answer as well) Related topics
72830
Are the string literals we use inside functions automatic variables? Or are they allocated in heap which we have to free manually?  I've a situation like the code shown below wherein I'm assigning a string literal to a private field of the class (marked as ONE in the code) and retrieving it much later in my program and using it (marked as TWO). Am I assigning a variable in the stack to a field in ONE? Can the code be referencing to a dangling pointer which in this case worked because the program was small enough?  I've compiled and ran it, it worked fine but I'm having a strange crash in my actual program where I'm assigning string literals to fields of the class like this and I suspect the case I mentioned above.  #include &lt;iostream&gt;  using namespace std;  class MemoryLeak { private:     char *s; public:     MemoryLeak() {}      void store()     {         s = "Storing a string"; // ONE     }      char *retrieve()     {         return s;     } };  int main() {     MemoryLeak *obj = new MemoryLeak();     obj-&gt;store();     cout &lt;&lt; obj-&gt;retrieve() &lt;&lt; endl; // TWO     delete obj;     return 0; }   Should I be declaring the variable "s" as a char array instead of a pointer? I'm planning to use std::string, but I'm just curious about this.  Any pointers or help is, as always, much appreciated :) Thanks.
98970
I'm not sure if this is a strange thing to do or not, or if it is some how code smell...but I was wondering if there was a way (some sort of oop pattern would be nice) to "cast" a base type to a form of its derived type. I know this makes little sense as the derived type will have additional functionality that the parent doesn't offer which is in its self not fundamentally sound. But is there some way to do this? Here is a code example to so I can better explain what I"m asking.  public class SomeBaseClass {     public string GetBaseClassName {get;set;}     public bool BooleanEvaluator {get;set;} }  public class SomeDerivedClass : SomeBaseClass {     public void Insert(SqlConnection connection) {           //...random connection stuff           cmd.Parameters["IsItTrue"].Value = this.BooleanEvalutar;           //...     } }  public static void Main(object[] args) {     SomeBaseClass baseClass = new SomeBaseClass();     SomeDerivedClass derClass = (SomeDerivedClass)baseClass;      derClass.Insert(new sqlConnection()); }   I know this seems goofy but is there any way to accomplish something of this sort?
80088
When referencing class variables, why do people prepend it with this? I'm not talking about the case when this is used to disambiguate from method parameters, but rather when it seems unnecessary.  Example:  public class Person {             private String name;      public String toString() {         return this.name;     } }   In toString, why not just reference name as name?  return name;   What does this.name buy?   a stackoverflow question whose code has this pre-pending.