FAQ Database Discussion Community


recursively editing member variable: All instances have same value

python-3.x,recursion,tree,member
I want to create a Tree data structure that consists of TreeNode objects. The root is a TreeNode. Each TreeNode has one parent TreeNode and a list of children TreeNodes. The Tree is built up recursively. I simplified the code to make the example not too difficult. The function get_list_of_values_from_somewhere...

c++ private static member variables compared to free nonmember

c++,private,member
I'm relative new to C++ and have a question regarding private static member or "free nonmeber". I can write my code like this: // MyClass.h - Version 1 class MyClass { public: MyClass(); ~MyClass(); private: static int iValue; }; // MyClass.cpp int MyClass::iValue = 123; The other way without...

Non-friend, non-member functions increase encapsulation?

c++,encapsulation,member,non-member-functions
In the article How Non-Member Functions Improve Encapsulation, Scott Meyers argues that there is no way to prevent non-member functions from "happening". Syntax Issues If you're like many people with whom I've discussed this issue, you're likely to have reservations about the syntactic implications of my advice that non-friend non-member...

Definition of function which is the class member

c++,function,class,private,member
I have two functions, which are private members of class "Data": class Date { private: bool leapYear(int y); void fillDate(int d, Month m, int y); }; So, where is the best to define this functions: in class definition; in header file outside the class; or in ".cpp" file? ...

C++ Isn't this a useless inline declaration?

c++,inline,private,member,protected
This is another question about inlining a function. But I will take possible comments and answers right away: Defining a function inside a class makes it inline automatically. The same behaviour can be achieved by marking a function with inline outside of the class. An inline function doesn't have to...

Swift ViewController does not have member named

variables,swift,core-data,member
OK, I've been through all of the threads that supposedly deal with this problem and none of them seem to rectify my issue. Basically I have a tableview setup with core data and when I segue into the next view controller I want to pass some data. As you know...

C++: How to find host object from pointer to member variable

c++,pointers,member,host-object
Here we have our simple node struct which might be used to implement a double linked list. template <class T> struct node { node<T> *prev = NULL; node<T> *next = NULL; T data; }; Supposing we don't know or have reference to a node object/instance, but we do have a...

Accessing array member codeigniter

arrays,codeigniter,member
I want to access this arrays member named 'tag', how can i do that? Array; array (size=1) 0 => object(stdClass)[23] public 'tag' => string '20' (length=2) ...

What's the difference between the square bracket and dot notations in Python?

python,object,collections,attributes,member
I come from a Javascript background (where properties can be accessed through both . and [] notation), so please forgive me, but, what, exactly is the difference between the two in Python? From my experimentation it seeems that [] should always be used, both to get the index of a...

corosync-objctl: command not found

member,high-availability,totem
I installed corosync from apt repository in ubuntu 14.04.1 and configured two pc to setup the connection. apt-get install corosync corosync-dev The version of corosync is corosync: Installed: 2.3.3-1ubuntu1 Candidate: 2.3.3-1ubuntu1 Version table: *** 2.3.3-1ubuntu1 0 500 http://ca.archive.ubuntu.com/ubuntu/ trusty/main amd64 Packages 100 /var/lib/dpkg/status To check the members in ring, using...

Member Variables in Python?

python,variables,concatenation,member
I'm trying to create a console input program in which a user can add HTML to a file. So if you pressed B(for bold) and then your input was "test" It would put "test" into the file. The problem is, there is only one function "SaveToFile" that actually should be...

scala, using class member function as first class functions

function,scala,class,member
I want to assign a member function of a class instance as a first class function to a variable: class A(val id:Int){ def f(u:Int)=id+u } val a= new A(0) val h=a.f // fails: interpreted as a.f(with missing parameter u) val h1 = (u:Int)=>a.f(u) // OK and does what we want...

Copy contents of a class member vector into another vector and then swapping them back

c++,class,vector,member
So I have two classes in the following format: class HashMinHeap { private: vector<int> MiniHeap; public: ... ]; class HashTable { private: vector<HashMinHeap*> table; public: ... }; I want to create a second vector, vector <HashMinHeap*> table2, copy the contents of table into table2, then I'm going to do some...

ReNesting Resource Routes in Rails

ruby-on-rails,routing,haml,member,nested-resources
So I just made one of my objects a nested resource of my user object. Now all of my links don't work and my index won't show. I am getting the error: /views/photos/index.html.haml where line #8 raised: No route matches {:action=>"show", :controller=>"photos", :id=>nil, :user_id=>nil} missing required keys: [:id, :user_id] with...

Cant access member of object

javascript,object,numbers,leaflet,member
I have an issue to access a member in the object DOM, because the object name is a number! I am working with leaflet.js and I created a layer with a path. Now I want to access the polylines latLngs. In this case I wanna access the layer "100". The...

C++ class member check if not a template

c++,member
template instantiation check for member existing in class explains how to check if a class member exists in a template. However, given a set of processes within a switch (NOT a template) is there a way to handle a member check case. It should be similar to something like this....

Constructor destroys member variables

c++,variables,constructor,member
Why are initialized member variables deleted when calling the constructor for a second time? Example: class MyClass { private: unsigned myValue; public: MyClass(void) { this->myValue = 1337; fprintf(stderr, "myValue: %d\n", this->myValue); } MyClass(int myFirstValue) { fprintf(stderr, "myValue: %d\n", this->myValue); } }; int main() { /* Constructor is called */ MyClass...

QWidgets as members or not?

c++,qt,constructor,member,qwidget
I just started to learn how to use Qt and I wonder if I should describe the Widgets (e.g. an array of Pushbuttons) in the QMainFrame class as private members or should I define them in the constructor of QMainFrame? What's the common implementation and what are the (dis)advantages of...

How to refer C structure member in mails

c,structure,member
This is not strictly programing question. I have been coding in C++ in past. During mail conversation I was able to address class member I by doing foo::bar. But now I am coding in pure C and mailing with people that does not necessarily know C++. I am wondering if...

C++ Member Function Pointer From other class

c++,function,pointers,member,pointer-to-member
I am creating a console menu in C++ and I want to give every item in my menu a callback function, so when an item is selected, a different function is called. So far, I have this code: #include <iostream> #include <vector> using namespace std; class Core { public: void...

Initialize members with deleted default constructor

c++,constructor,member,default-constructor
In C++, if I want to have a member of a class that has no default constructor, I need to explicitly initialize it like this: class a { a(int) { } }; class b { a x; b() : x(3) { } }; However, sometimes the initialization for, say, x,...

Access rawValue of enum in array in Swift

arrays,swift,enums,max,member
I'm trying to use maxElement to work with enums in an array, accessed by .rawValue as shown in the example below: var planets: [Planets] = [.Mars, .Earth, .Jupiter] maxElement(planets.rawValue) I could just use other methods to get the max rawValue but it would be so nice and easy if it...

Passing an ifstream variable between members of the same object, C++

c++,file,class,object,member
Goal: Using the class variable so that an ifstream declared in an object's member can be used by the following member of the same object, without having to use function header parameter passing. Problem: The local ifstream of the created object test isn't being re-used in the second member of...

method overriding Vs class variable overriding in java

java,methods,member,overriding
I was just trying some sample code for checking class variable overriding behavior in Java. Below is the code: class A{ int i=0; void sayHi(){ System.out.println("Hi From A"); } } class B extends A{ int i=2; void sayHi(){ System.out.println("Hi From B"); } } public class HelloWorld { public static void...

c# accessing struct members within class' methods

c#,struct,member,non-static
i'm trying to write a simple game. I want to design a "movement controller" object, that would handle move instructions from the engine. I would also like for this object to expose a method, that would check its state and return true/false depending if it's ready to move or not....

C++ template meta-programming member function loop unrolling

c++,templates,metaprogramming,member
I have just started to use template meta-programming in my code. I have a class which has as a member which is a vector of a multi-dimensional Cartesian points. Here is a basic setup of the class: template<size_t N> class TGrid{ public: void round_points_3(){ for(std::size_t i = 0; i <...