w3hello.com logo
Home PHP C# C++ Android Java Javascript Python IOS SQL HTML videos Categories
How Does Getting the Address of a Class Member Through a Scope Resolution Operator Work When Using a Pointer-to-Member?
When you declare a pointer to member data, it isn't bounded to any particular instance. If you want to know the address of a data member for a given instance you need to take the address of the result after doing .* or ->*. For instance: #include <stdio.h> struct A { int n; }; int main() { A a = {42}; A aa = {55}; int A::*ptm = &A::n; printf("a.*ptm: %p ", (void *)&(a.*ptm)); printf("aa.*ptm: %p ", (void *)&(aa.*ptm)); } prints as one possible output: a.*ptm: 0xbfbe268c aa.*ptm: 0xbfbe2688

Categories : C++

Strange behavior with volatile write on class member vs struct member
The time difference is most likely a consequence of the var volatileLong = new VolatileLongClass(); within the loop; that statement causes the compiler to--once--allocate space to hold a VolatileLongClass reference, and then on each pass through the loop create a new object and store a reference into that location. By contrast, the statement var volatileLong = new VolatileLongStruct(); causes the compiler to--once--allocate space to hold a VolatileLongStruct instance, and then on each pass through the loop mutate that pre-existing instance by zeroing out all its data (using normal, rather than volatile, writes). Note that if code will require structs fields to have particular multi-thread semantics, such fields should often be made public, and the struct should be regarded as being a gro

Categories : C#

How do I create a table that has a composite key each member of which is a foreign key member to other tables
By convention, cascade deletes are handled by the introduction of the actual foreign key into your model. If you use a non-nullable foreign key, it will require delete. Use a nullable foreign key to turn it off. Change your class to the following by making the foreign keys nullable: [Table("CustomerAppointments")] public partial class CustomerAppointment { [Key,Column(Order=0)] public int? CustomerId { get; set; } [Key,Column(Order=1)] public int? VehicleId { get; set; } public DateTime? AppointmentDate { get; set; } public DateTime? AppointmentTime { get; set; } public string AvailableDays { get; set; } //other fields [ForeignKey("CustomerId")] public virtual Customer Customer { get; set; } [ForeignKey("VehicleId")] public virtual

Categories : C#

Java - reducing visibility - member data vs member functions
By declaring a new instance variable named x in Child class , you are hiding the super class instance variable x. Within a class, a field that has the same name as a field in the superclass hides the superclass's field, even if their types are different.Within the subclass, the field in the superclass cannot be referenced by its simple name. Instead, the field must be accessed through super. Read the tutorials for more information. You can write a method in class Child as: public int getParentDataMember() { return super.dataMember; } And access the member as : System.out.println("Child dataMember = " + c.getParentDataMember());

Categories : Java

Static member array of pointers to member functions
If you have non static member functions with no arguments and returning bool you should write something like typedef bool (Hand::*hfunction_non_static)(); hfunction_non_static f_non_static [] = { &Hand::has_sflush, &Hand::has_poker, ....... }; Hand h; (h.*f_non_static[0])(); If you have static functions you should write something like typedef bool (*hfunction_static)(); hfunction_static f_static [] = {&Hand::has_sflush, ....}; f_static[0]();

Categories : C++

Don't inherit private member if it's accessed by public member
This situation -- where a class has data members that you do not want to inherit -- is called the "Refused Bequest" antipattern, and what it generally means is that your inheritance relationship is wrong. Rather than having B extend A, you need an interface C that both implement independently. If there is significant implementation that you do want to share, then perhaps you could introduce an abstract base class that A and B could share.

Categories : Java

How to allow templated functor work on both member and non-member functions
You will definitely need some kind of default implementation for a class. But the good news is that this can be foreseen by the logger class itself. Just replace template<typename RetType, typename Arg1Type, typename Class> with template<typename RetType, typename Arg1Type, typename Class=DefaultDummyClass> of course the DefaultDummyClass has to be foreseen, but it no longer has to be provided by somebody who wants to use the logger class.

Categories : C++

Non-member operator as private member of foreign class
It is not possible to make a version of operator == the way you want. It can't be made static. If it is a member, then it must take one argument. If you are willing to "duplicate code", then you can play tricks with namespaces. Your generic interpreter could be a template that takes a language specific derived class as a template parameter. It in turn calls a templated operator== based on a language specific token. template <typename TOKEN> bool operator == (const std::string &l, const TOKEN token) { return token == l; } // Language specific interpreters inherit from this template template <typename LANG> class Interpreter { public: void interpret () { std::string s("hi"); if (s == LANG::KEYWORD_ELSE) {} } }; Each language specific subclass

Categories : C++

Select one member from JSON result based on member value
You could put them all into an array of objects, and then have some sort of key on the objects, or you could just loop through the results: $.each(sizeResults, function(index, value) { if (value.label == "Large") { photoURL = value.source; return false; // breaks out of the loop. } }); Certainly not efficient, but it should be fast enough...

Categories : Javascript

Error: invalid use of member in static member function
Your class and member (screen) are not static, which means they don't actually exist. You can't access a non static member in a static function. Try to make your data members to be static.

Categories : C++

accessing private member of member class
public class A { private int myMember; public int getMyMember() { return myMember; } public void setMyMember(int myMember) { this.myMember = myMember; } } public class B{ private A myA; public B() { myA = new A(); myA.setMyMember(0); int a = myA.getMyMember(); } }

Categories : Java

overloading a member inside another member
First I would suggest use std::string in favour of char[]. It will save a lot of trouble. For reading ISBN I would write something like this: bool ISBN::read(istream& is) { ISBN result; // reading into result std::swap(*this,result); return !quit; } Or even better (as a non member function): std::istream& operator>>(istream& is, ISBN& obj) { ISBN result; // reading into result is(!quit) is.clear(std::ios_base::failbit); std::swap(obj,result); return is; } In any way you should RAII classes for your resources. In your special case std::string instead of char[].

Categories : C++

data member 'vec' cannot be a member template
Vector always need a class T as template. But the template should be put ahead of class declaration. You probably mean template<class T> class A { private: std::vector<T> vec; };

Categories : C++

How to choose between member and non-member functions?
If you need to calculate the area of polymorphic Shape objects, then Scott's advice is not for your case. Because you cannot calculate the area with an external function, because in fact you don't have public access to the information that is required. Namely, whether the object is actually a circle, a rectangle, or something else. So this is a job for virtual functions. In fact, in Scott's psuedo-code algorithm for determining the correct placement of a function (taken from this article, as I do not have the book), the first test is this: if (f needs to be virtual) make f a member function of C;

Categories : C++

call a class member to get default parameters for another member function of same class
listGraph getPlanarGraph(const vector<int> &nodeSe=this->getLabels()); ... isn't possible because when a method is being called, this refers to whichever class instance is calling the method, not to an instance of the class to which the method belongs. this only refers to the instance of the class to which the method belongs once the method is being executed. As to why it isn't possible, the line above is somewhat similar to calling the method like this: x xinstance; const vector<int> nodeSe labels = this->getLabels(); listGraph lg = xinstance.getPlanarGraph(labels); This code would work, but you can see clearly that this refers to the instance of whatever class contains the lines of code above, not to xinstance. As @Ivan Aucamp pointed out in the commen

Categories : C++

__class_ data member in python, how it is different from static data member in java
The problem is this line while not PizzaShop.pizza_stock: This will stop immediately if pizza_stock is nonzero. Which it always is. You probably intended to write while PizzaShop.pizza_stock: Anyway, if you want to find the details on how values, classes, etc. behave in Python, you should check the docs. It's very different from Java. P.S. The following is unnecessary as str.format has a shorthand for calling repr. Also, you shouldn't call magic methods like .next directly. Use the builtin next() instead. print "{}".format(repr(pizza_order.next())) Should be print "{!r}".format(next(pizza_order))

Categories : Python

MySQL Query to Determine if Member is a Friend of a Friend to another Member
For a moment, don't think of it as of a table. In order to qualify for a mutual friend, a user must be in my circle AND other user's circle. Intersection of sets. So you have: SELECT * FROM profiles WHERE id IN (SELECT viewers friends IDs) AND id IN (SELECT the viewed users friends IDS); Write sub-queries is left as an exercise ;)

Categories : PHP

In python ,how to add class member function pointer in class member?
UPDATE: There's no way to get the syntax you want, since there's no way for self.__class__.functionMap[itemName] to know which instance it should operate on. However, if you pass self explicitly, you can get very close: class MyClass: def __detectWhichItemClicked(self): itemName = getItemName() if itemName in self.functionMap: # Pass self into the call self.functionMap[itemName](self, arg) ... # This goes after the __handle methods are defined. functionMap = { "ITEM1": __handleRightClickItem1, ... } # Equivalent. getattr(obj, "foo")(arg) getattr(MyClass, "foo")(obj, arg) obj.foo(arg) MyClass.foo(obj, arg) # Also equivalent bound_method = obj.foo # or getattr(obj, "foo") bound_method(arg) # Still equivalent u

Categories : Python

C++ member vs non-member operator+
There is a very strong reason for it to be a non-member function: symmetry between LHS and RHS of an + expression. In the case of std::complex, it is implicitly convertible from a scalar type (int, double etc), so the following would not work if the operator were a member: std::complex<double> c1; std::complex c2<double> = 5.0 + c1; whereas the following would: std::complex c2<double> = c1 + 5.0; That inconsistency wouldn't make much sense. A non-member binary operator allows the implicit conversions to take place. Note: In my experience with mathematical vector types, it is often desirable to provide arithmetic operators involving other vector types: template <typename V> Vector2 operator+(const Vector2& lhs, const V& rhs) { Vector2 ret = lhs;

Categories : C++

How to access a non-static member from a static member function in C++?
No, there is no way of calling a non-static member function from a static function without having a pointer to an object instance. How else would the compiler know what object to call the function on?

Categories : C++

Member function pointer, pass function as argoument of a non member function
You need an instance of power to call the function pointer on like this: double chordL(T& instance, T::*fm, double p1, double p2){ return sqrt(pow(instance.*fm(p1) - instance.*fm(p2), 2) + pow(p1 - p2, 2)); }

Categories : C++

How to pass a member function to a function used in another member function?
Use a pointer to member function: struct Foo { void f(int, int) {} void g(int, int) {} void execute((Foo::*ptmf)(int, int), int a, int b) { // invoke (this->*ptmf)(a, b); } }; Usage: Foo x; x.execute(&Foo::f, 1, 2); // calls x.f(1, 2) x.execute(&Foo::g, 2, 1); // calls x.g(2, 1) These pointers work as expected with virtual functions.

Categories : C++

Linkedin API is asking for member ID
In "Get My Connections" you'll get the list of your connections.From there between tags you'll get member id associated with each of your connection.Give this as parameter and check. provide url like this http://api.linkedin.com/v1/people/~:(id,first-name,last-name,headline,maiden-name,picture-url,formatted-name,phonetic-last-name,summary,location:(name,country:(code)),industry,distance,num-recommenders,current-status,current-share,network,skills,phone-numbers,specialties,date-of-birth,main-address,positions,email-address,educations:(school-name,field-of-study,start-date,end-date,degree,activities)) to get all the profile information Hope it helps

Categories : Iphone

‘SIFT’ is not a member of ‘cv’
SIFT and SURF were moved to nonfree module. You need to add #include <opencv2/nonfree/nonfree.hpp> header and link with opencv_nonfree library.

Categories : Osx

Invalid use of 'this' in non-member
If you are talking about QPainter painter(this); you are using the this pointer in main. The this pointer is for member functions of an object. Your main function doesn't have a this pointer to use.

Categories : C++

Get class member by its name
for(int i=0; i<10; i++) ((ComboBox)FindControl(string.Format("cb_{0}", i))).SelectedIndex=1; I haven't ran this code - so it might not be perfect - but a good starting point

Categories : C#

Cast by member value
NULL->derivedspecific() won't compile ((derived*)NULL)->derivedspecific() is undefined behaviour (segmentation fault on most platforms there is a mechanism which is specifically designed to support this kind of behaviour, i.e. dynamic_cast which goes like: #include <typeinfo> class base { public: virtual ~base(){}; }; class derived1 : public base { public: void derived1specific() const {} }; class derived2 : public base { public: void derived2specific() const {} }; int main() { // use pointers base* test = new derived1; derived2* d2 = dynamic_cast<derived2*>(test); if(d2) d2->derived2specific(); derived1* d1 = dynamic_cast<derived1*>(test); if(d1) d1->derived1specific(); // o

Categories : C++

C++ Only Allow a member variable to be set once
Since Game::screen is private, it cannot be accessed by the derived class. While a caller of GetScreen() can access the Screen object, he cannot modify what the Game's stored screen points to. So you're perfectly fine with e.g. providing these two overloads: class Game { Screen *screen; protected: const Screen* GetScreen() const; Screen* GetScreen(); }; None of them allows the derived class to modify the screen pointer itself, so it cannot "reset" it to point somewhere Game wouldn't want it to point.

Categories : C++

C++ member function using another member function
double (*fct)(double) declares an argument of type "pointer-to-function". You need to declare that as a "pointer-to-member function" instead: double (CDS::*fct)(double). Furthermore, you need an object on which you call the pointer-to-member: (someObject->*fct)(someDouble);

Categories : C++

Struct with no member
It is a forward decl, here is where it is defined: http://lxr.free-electrons.com/source/include/linux/mm_types.h?v=3.4

Categories : C

Structure member declaration with " : 1 "
It's something called a "bit field". It's for memory optimization. It lets you store a type in less space than you would need otherwise. (code from the above link). #include <stdio.h> #include <string.h> struct { unsigned int age : 3; } Age; int main( ) { Age.age = 4; printf( "Sizeof( Age ) : %d ", sizeof(Age) ); printf( "Age.age : %d ", Age.age ); Age.age = 7; printf( "Age.age : %d ", Age.age ); Age.age = 8; printf( "Age.age : %d ", Age.age ); return 0; } Outputs: Sizeof( Age ) : 4 Age.age : 4 Age.age : 7 Age.age : 0 Notice how assigning to a value higher than 23 reduces the size of Age.age to 0? This is because that :3. This also means that your unsigned char active:1; example is great for storing booleans: it can only be true or false,

Categories : C

An issue with a non-member function
You do not necessarily need to make the function member. You can have at least two ways to solve it in a different manner. The problem is that you are having all this in a situation where a Sound object is not yet defined if I understand correctly. 1) You can refactor your code a bit as demonstrated below. header file: class Sound { public: Sound(); doStuff(); } cpp file: void non_member_function(Sound sound) Sound::Sound() { non_member_function(*this); } Sound::doStuff() {} void non_member_function(Sound sound) { sound.doStuff(); } 2) if you insist on the scenario aforementioned, you put a Sound sound forward declaration before the non-member function to get the type recognized. Or, you can just put the declaration after the class declaration. header file: class Soun

Categories : C++

Cannot add the same member twice to a SerializationInfo object
The problem is occurring most likely because the same element at the same node is being added to the UI map. I would go through it with a fine tooth comb and check for any duplicates that might be occurring.

Categories : C#

Forms is not a member of Windows
You're using VSE2k12 "for Web". I'm not convinced that's going to include stuff explicitly marked as being for "Windows-based applications that take full advantage of the rich user interface features available in the Microsoft Windows operating system" :-) You may need to consider getting a more expansive edition of the development environment.

Categories : Dotnet

What does *New() mean when declaring member function?
This static vtkBorderCallback *New(); is a static member function called New, taking no arguments, and returning a pointer to vtkBorderCallback. In the implementation, you should omit the static. You also need to place the function in the scope of its class: vtkBorderCallBack* vtkBorderCallback::New() {// ^^^^^^^^^^^^^^^^^^^ return new vtkBorderCallback; // danger! Caller needs to delete this eventually }

Categories : C++

How to share a member between policies?
Here's a way to do CRTP without having policies inherit from hosts template <typename DerivedT> struct p1 { DerivedT& derived() { return *static_cast<DerivedT*>(this); } const DerivedT& derived() const { return *static_cast<const DerivedT*>(this); } void f1() { derived().member += 1; } }; template <typename DerivedT> struct p2 { DerivedT& derived() { return *static_cast<DerivedT*>(this); } const DerivedT& derived() const { return *static_cast<const DerivedT*>(this); } void f2() { derived().member *= 2; } }; struct host : public p1<host>, public p2<host> { double member; };

Categories : C++

what’s the type of this class member a?
The line typedef long double Money; is a give away i.e. a is of type Money and Money is a long double

Categories : C++

Is it possible to have an "auto" member variable?
You can, but you have to declare it static and const: struct Timer { static const auto start = 0; }; A working example in Coliru. With this limitation, you therefore cannot have start as a non-static member, and cannot have different values in different objects. If you want different types of start for different objects, better have your class as a template template<typename T> struct Timer { T start; }; If you want to deduce the type of T, you can make a factory-like function that does the type deduction. template<typename T> Timer<typename std::decay<T>::type> MakeTimer(T&& startVal) { // Forwards the parameter return Timer<typename std::decay<T>::type>{std::forward<T>(startVal)}; } Live example.

Categories : C++

does not implement interface member
Your class GetVenues does not implement the method mentioned in your error message. Where exactly are you stuck? GetVenuesByLocation(string search) is defined in the class Venue. I have noticed that this question is starting to garner interest. The issue here is very easy: your class does not implement (even if it's abstract, you have to define them) all methods defined in the interface. Your IDE should warn you of this before compiling.

Categories : C#

HQL MEMBER OF to criteria conversion
you need to use Restrictions.eqProperty as following. Hope this will help you. DetachedCriteria hsql = DetachedCriteria.forClass(Transaction.class, "t") .addAlias("t.history", "h") .addAlias("t.group", "g") .add(Restrictions.or( Restrictions.isNull("t.group"), Restrictions.eqProperty("h.account", "g.account") ));

Categories : Hibernate



© Copyright 2017 w3hello.com Publishing Limited. All rights reserved.