w3hello.com logo
Home PHP C# C++ Android Java Javascript Python IOS SQL HTML videos Categories
Left derivation and right derivation for the following grammar
The leftmost and rightmost derivation are the same in this case, which is as you showed. The leftmost derivation expands the leftmost nonterminal first; the rightmost derivation expands the rightmost nonterminal first. Wikipedia has good examples. For the grammar S → S + S S → 1 S → a This is a leftmost derivation: S → S + S → 1 + S → 1 + S + S → 1 + 1 + S → 1 + 1 + a This is a rightmost derivation: S → S + S → S + a → S + S + a → S + 1 + a → 1 + 1 + a

Categories : C

Trouble understanding C++ derivation
This is all about "static polymorphism", aka method overloading. The particular version of operator<< is chosen by the compiler based on the compile-time type of the variables it sees; since get_piece() returns Piece, that's the version of operator<< that is chosen. I have to point out that you are wrong about the equivalent Java program: Java method overloading is also arbitrated by the compiler, and is based on compile-time types. A truly equivalent Java program would display Piece, as well.

Categories : C++

Unqualified IDs and Template Classes
The error message states that CIterator<T> isn't considered a template. This is because it is a dependent name and the compiler can only really determine at instantiation time that it, indeed, is a nested template. The fix for the problem is to tell the compiler that it actually is a template: template <class T> typename CList<T>::template CIterator<T> CList<T>::push(T const& v) { ... } The reason the compiler doesn't know if CList<T>::CIterator<T> is a template is that the class CList<X> could be specialized for some type X to not have a nested template inside. However, the compiler only finds out about these specializations when the template is instantiated.

Categories : C++

How to convert template classes?
A possible approach is defining a visitor pattern, but the cost of implementing the visitor might be large if you want to support many different wrapped types (i.e. if it is not just a small subset). Another problem you would get is that the conversions would be (have to be) dynamically dispatched, so they can fail at runtime and you would have to provide mechanisms to detect that and act on that then (exceptions come to mind). Nothing horrible...

Categories : C++

Template Classes when instance variables necessary
Just a trick, passing a as the input param to the method should help you: public int calc(int a) { int c = a + 4; return c; } I think even if you don't do it, then using this should use the value of a of the calling object: public int calc() { int c = this.a + 4; return c; }

Categories : Java

Using extern template class with STL classes
It's by standard that the STL data structures are implemented in header files, so this isn't VS10 specific. Why do you want to limit to only one object file? There are problems splitting templates between headers and source files - you can search for that.

Categories : C++

Error getting template classes to work
In your class declaration you have this: T *heap; In doubleHeapCap you have this: minHeap *temp; // code... temp = heap; If T is int then you are trying to assign an int* (heap) to a minHeap<int>* (temp). Basically, make temp into a T*, too, and it should work. Or you could just dispense with temp altogether and write: std::swap(heap, newHeap); delete[] newHeap;

Categories : C++

Css classes not added in new layout template in WebSphere Portal
Just adding a class name to an element does not in any way create that class in any css entry. You will have to manually add that class to the css along with any rules for styling you are wishing to have in place.

Categories : CSS

Conditional compilation of overloaded functions in template classes
If you were trying to implement a functor this way there would be a number of obvious flaws in the design; I assume, and you seem to make it clear on the comments, that the code is just, well, an example used to state your case. Here are a couple of solutions to the problem: template<class T> struct Trait{ typedef T type; typedef T mock_type; }; template<> struct Trait<void>{ typedef void type; typedef int mock_type; }; template <class Arg> class FunctionWrapper { public: void Invoke(void){_fn();} void Invoke(typename Trait<Arg>::mock_type arg){_fn(arg);} boost::function<void(typename Trait<Arg>::type)> _fn; private: }; template <class Arg> class FunctionWrapper2 { public: FunctionWrapper2(const bo

Categories : C++

Java name clash, how to rewrite the program with template classes
Make the method generic: public static T[] toArray(List<T> list) { T[] data = new T[list.size()]; for(int i = 0; i < data.length; i++) data[i] = list.get(i); return data; Might not be syntactically correct, a while since ive written java :) The solution should hold though

Categories : Java

Unknown Method Return Type with Polymorphic Template Classes in C++
Return value of GetData can be template parameter: template <class T> class MatrixImpl { public: typedef T DataType; DataType GetData(); }; template <class T> class Matrix { public: typedef MatrixImpl<T> Impl; typedef typename Impl::DataType DataType; DataType GetData() { return data_->GetData(); } private: Impl* data_; };

Categories : C++

Possible to access private types in base classes via template indirection
I've modified your example a little, so w/ my gcc 4.8.1 now everything work as expected (intended). Few notes about original code: when you wanted to test accessibility of a Log (using use_logger) the primary misunderstanding that use_logger is an external class for A, B, C, D! It can't (by design) to access anything 'cept public members of that classes! the second aspect about your checker: passing the type Log into it, you going to loose "context" -- i.e. the checker doesn't know (and it have no way to realize it w/ that design) "is this type is actually a nested type of something else?" and finally use_logger just incorrect: it always reinterpret 0 to a P* -- there is no other possibilities (ways to interpret) this code... the main idea behind such checkers is to form a set of "matc

Categories : C++

Implicit initialization of static member variables for template classes
If the compiler implicitly instantiates a class template that contains static members, those static members are not implicitly instantiated. The compiler will instantiate a static member only when the compiler needs the static member's definition. This behaviour is backed by the C++ standard and here is the passage 14.7.1p1 ... The implicit instantiation of a class template specialization causes the implicit instantiation of the declarations, but not of the definitions or default arguments, of the class member functions, member classes, scoped member enumerations, static dataembers and member templates; and it causes the implicit instantiation of the definitions of unscoped member enumerations and member anonymous unions. and another relevant section found by @gx_ 14.7

Categories : C++

How can I structure my MustacheJS template to add dynamic classes based on the values from a JSON file?
For conditionals, you can use {{#toll_free}} {{toll_free}} {{/toll_free}} Which will only display the content in between the tags if it is not null, undefined, or false. Otherwise, it will completely ignore that content. For the listing icons class, you should simplify your html to use the li for both the icon and the text. That way you can surround the whole thing in conditionals from Mustache and avoid having to deal with using such classes entirely. An example would be: {{#toll_free}} <li><i class="icon-phone"></i>{{toll_free}}</li> {{/toll_free}} Using CSS, you can achieve the same look you have now with some padding. I made a fiddle to show this and the working template code, based roughly on your example: http://jsfiddle.net/NGwge/

Categories : Javascript

C++: "Invalid covariant return type" errors in nested classes with methods returning template-based objects
The function with the signature B::test(void) returns an object of type Q<A>, while C::test(void) (which is the same signature, so you're overwriting the function) returns Q<B>. I think that is impossible. As far as I know it is impossible to overload a function by return type and overwrites of parent functions need to stick to the same return type. From the Standard §10.3/7 The return type of an overriding function shall be either identical to the return type of the overridden function or covariant with the classes of the functions. If a function D::f overrides a function B::f, the return types of the functions are covariant if they satisfy the following criteria: both are pointers to classes, both are lvalue references to classes, or both are rvalue references

Categories : C++

Dynamic Compilation in Memory for Java for classes and classes that have dependencies on those classes
I believe your problem is in the JavaSourceFromString class, which needs to encode a URI for the class name: @Test public void test(){ Map<String, String> code = new HashMap<String, String>(); code.put("example.A", "package example; " + "public class A { " + " public A() { " + " doSomething(); " + " } " + "}"); code.put("example.B", "package example; " + "public class B { " + " private A holderForA; " + " public B() { " + " this.holderForA = new A(); " + " } " + "}"); JavaCompiler compiler = ToolProvider.getSystemJavaCompiler(); Diag

Categories : Java

Meteor template: Pass a parameter into each sub template, and retrieve it in the sub-template helper
When you use {{> child myParam}}, it's calling the child template and associates myParam as current template data context, meaning that in the template you can reference {{paramName}}. In someOtherHelper you could use this.paramName to retrieve "paramValue". However, when you're using {{#each nodes}}{{> child}}{{/each}}, it means that you pass the content of the current list item (fetched from a LocalCursor or directly an array item) as the template data of child, and you can reference the list item properties using {{field}} in html or this.field in js. What's happening here is when you call {{> child myParam}}, the myParam helper content OVERWRITES the current node item as template data, that's why it's messing your node list. A quick (dirty) trick would be to simply extend t

Categories : Meteor

Which part of JLS said anonymous classes cannot have public/protected/private member classes
My final answer consists of two thesis: There is not strong declaration of restrictions for anonymous class members modifiers in the JLS. I.e. there isn't such part of JLS. But according to JVM specs anonymous classes aren't members of class: JVM 7 spec: 4.7.6 The InnerClasses Attribute states: If C is not a member of a class or an interface (that is, if C is a top-level class or interface (JLS §7.6) or a local class (JLS §14.3) or an anonymous class (JLS §15.9.5))... so, according to 8.5 Member Type Declarations A member class is a class whose declaration is directly enclosed in another class or interface declaration. anonymous classes are not member classes. so, according to 8.1.1. Class Modifiers: The access modifiers protected and private (§6.6) pertain

Categories : Java

Alternative to static nested classes in C# for grouping a classes public methods?
Employee theEmployee = new Employee(); Would give you an Employee object to work with. With this you could change the values of the Employee class from DataBaseHandler

Categories : C#

PHP parser/execution order, classes extending classes defined later in file
The order in which you define those classes in the file does not matter. PHP does not simply go through your script line by line. It will parse the whole file, load any classes, and execute the procedural code. If I remember correctly, this hasn't always been the case. I think PHP 3 had difficulty with this.

Categories : PHP

REST WCF - best approach to expose entities or convert custom classes to Entity classes vice versa
Fowlers first law of distributed object design states, "don't distribute your objects". This just means give them a copy and not the actual entity itself. If you were to create mirror copies of your entities in your data contract namespace, you retain much more flexibility, should your database schema need changing. If your data contract is initially identical to your entity, a tool such as AutoMapper will eliminate all the conversion code you need to write. Once configured, to convert your entity to your data contract becomes a 1 liner: Mapper.Map<CustomerDto>(customer); This takes your customer entity and gives you back a new customer dto. It's all convention based and works by matching up property names. Even if the data contract isn't entirely identical to the entity, yo

Categories : Wcf

TestNG is Running Classes Out of Order (Skipping Between Classes of Tests)
It turns out that the problem causing testNG to skip between classes was that I was initializing variables, classes, etc at the class level and not within a method (@Test). You can declare NULL objects but may not initialize them to any values anywhere except within a method. This includes the webdriver! So basically a setup method, first one run in the class is needed for any say variables that will need to be scoped to the class. Hope this helps somebody save some time. Thanks- JR.

Categories : Java

Java Abstract Classes: Returning "this" pointer for derived classes
unfortunately not. It would be good if you could do this public this withId(final String Id) { // doesn't work this.Id = Id; return this; } or just public this withId(final String Id) { // doesn't work either this.Id = Id; } or it would know that "void" methods are implicitly chained (as I believe one formal proposal suggested)

Categories : Java

Load classes from a jar file from a url to memory and then run the main class out of all the classes
You are on the right track (I think). The steps would be: Use URLConnection to open a stream to the JAR file. Read the stream and write it to ByteArrayOutputStream, and extract the byte array. Open a ByteArrayInputStream on the byte array, then wrap that in a JarInputStream. Iterate through the members of the entries of the JAR file, saving the entry information and buffering the entry file content in memory. Write a custom class loader that uses the in-memory cache of the JAR file entries and content. I can't point you at example code because I couldn't find any. (You pretty much have to cache stuff in memory since the JarFile API requires a RandomAccessFile and that implies that the data is in the file-system. On some systems you could create a temporary file, open a RAF on it, u

Categories : Java

C++ Prevent multiple inheritance of two classes by the derived classes of a certain class
Without really looking deeper, it looks like a typical problem that's used to be solved using static (compile time resolved) polymorphism. The basic approach for such frameworks is the CRTP meta programming pattern (simply because you introduce a strong policy for your inheriting class in how your parent/base classes can be used or combined). Have a look at how to provide type traits (there are some libs available to support this before C++11 stdandard compliance) concept checks (several libs support this, e.g. boost::concept_check) SFINAE and/or explicit (compile time) error conditions You might consider various discrete client helper (API) classes to aggregate interface implementations for your final classes; this refers to hiding certain implementations in compilation units and eve

Categories : C++

How to add the classes which are designed by me into java library ? (to use "import" keyword in other classes )
I am not sure if I understand this correctly but you need to make a jar file from your library project and then place that jar file into the project which wants to use that library. How do you do this depends mainly on the IDE which you are using. Add library in NetBeans Add library in Eclipse Add library in IntelliJ

Categories : Java

jquery select element with multiple classes based on set of classes
I don't know exactly what is the context of your question, but if it's, for example, color related, I guess there is a finite number of class. The way I would go about that would be the opposite. Instead of selecting the colors you have, filter away those that don't match your expected result. For example let's say you have for color class .blue, .red, .green, .yellow. To match the filters you used in your example, that would be :not(.blue,.green,.yellow) /*foo does not match, it is blue*/ :not(.green,.yellow) /*Match*/ :not(.yellow) /*Match*/ You still have to figure how to construct the set. But that's another question.

Categories : Javascript

Is the "Declaring Classes" Java tutorial wrong about private classes?
Top level classes cannot be private. However, nested classes can be private. See JLS The access modifier public (§6.6) pertains only to top level classes (§7.6) and to member classes (§8.5), not to local classes (§14.3) or anonymous classes (§15.9.5). The access modifiers protected and private (§6.6) pertain only to member classes within a directly enclosing class or enum declaration (§8.5).

Categories : Java

Losing sub classes' properties in a collection of inherited classes
You have some typos: public FilterDateRange(string source, int type, string name, DateTime fromDate, DateTime toDate) { base.Source = source; base.Type = type; base.Name = name; this.FromDate = FromDate; // set FromDate to FromDate (the property) this.ToDate = ToDate; } should be public FilterDateRange(string source, int type, string name, DateTime fromDate, DateTime toDate) { base.Source = source; base.Type = type; base.Name = name; this.FromDate = fromDate; // set FromDate to fromDate (the parameter) this.ToDate = toDate; }

Categories : C#

How to apply rule to classes when they are children of either of two parent classes?
Try the :not css selector: .special-price:not(.product-view) { } More information: https://developer.mozilla.org/en-US/docs/Web/CSS/:not JSFiddle: http://jsfiddle.net/b2bjJ/

Categories : CSS

Objective C Runtime - Built-in classes vs custom classes?
I'm not 100% clear what you mean by “built in classes”. Are classes in the Foundation framework “built in”? What about classes in UIKit? QuartzCore? AVFoundation? Social? Also, trying to distinguish classes like this seems like a bad idea, unless it's just for learning about the system. That said, perhaps it will suffice to get the bundle that a class was loaded from. That will tell you if the class was loaded from Foundation, or UIKit, etc. Look at +[NSBundle bundleForClass:].

Categories : Objective C

Prototyping a sub-classes to already defined classes in Javascript
And I want it applied all the instances of the class Sprite (past and future), not to one single instance. You're quite right that if you were dealing with a primitive (like your "testing" string), you could just add it to Sprite.prototype and it would appear on all Sprite objects without any crosstalk between them. Also if position was an array it would have been easy: just write Sprite.prototype.position=[0,0] While it's true that the array would show up on all Sprite objects, they would have the potential for cross-talk, because they'd all share the same array: var sprite1 = new Sprite(); var sprite2 = new Sprite(); Sprite.prototype.position = [0,0]; sprite1.position[0] = 42; console.log(sprite2.position[0]); // "42" If you don't mind them all sharing the same array/object

Categories : Javascript

Does Qt have general-purpose classes besides GUI-related classes?
As far as I know, Qt doesn't have image processing libraries. For that, you'll need to use something like OpenCV. Qt does have libraries for loading most common image types. However, Qt does extend beyond just GUI classes. There is a database module that's quite convenient. The concurrency/threading classes are nice. I've enjoyed making use of the Qt Networking classes. The FileIO classes are alright. These classes/modules are all useful for making platform-independent code. Things like image processing are mostly algorithmic and tend to be platform-independent by nature. So I think they fall out of the scope of the Qt framework. It shouldn't be too difficult, however, to simply find a library that does what you need and link that in to your project.

Categories : Qt

WEB-INF/classes Contains my classes in both .class and .java extensions
You can export the ".war" with source, probably that is what is happening in your situation. If you do "right click" on your project and select "export" > "war", you can "un-select" the "export source", among other details about the war to be generated. In your maven you probably have some details to "point" to include your source files (for example in this question it is shown how to include source files: How to generate a WAR with the source code in Maven?, you should remove those if you do not want the source files in the generated WAR). Excerpt of "configuration" part of pom.xml that does not include java source files: <configuration> <classifier>dev</classifier> <webappDirectory>${project.build.directory}/${project.build.finalName}-dev</webappDi

Categories : Java

Child classes and parent classes in Python
a better example is class Person: name="Person" def speak(self): print "Hi! Im %s"%slf.name class Dad(Person): name = "Dad" class Mom(Person): name = "Mom" class Child(Person): name = "a Child" age = 5 def speak(self): print "Hewwo, I am a %d year old child!"%self.age d = Dad() m = Mom() c = Child() c.speak() m.speak() d.speak() as to the difference (your question of static class access versus instance access) class Child: var3 = "whatever" c = Child() c.var3 = "something_else" print c.var3 print Child.var3

Categories : Python

Conflict between Smartclient classes and webservice classes
the namespace is not the same; in one, it is quite clearly SmartInstitute.Automation.SmartInstituteServices.CourseService, vs SmartInstitute. If this is a WCF service, then when you add the service there is an option in the IDE and command-line tools to re-use existing types - you must ensure this is enabled, and that the assembly which declares the types is specified. However, the easiest way to get this working is to have the DTO types (Cource, etc) in a dedicated simple assembly that is referenced and used by both tiers - then it usually "just works" - with WCF, at least. If you use 2.0-style asmx web-services, then : it will never work (it doesn't support this scenario). The other alternative is: treat the web-service proxy types as exactly that : a DTO type that is unrelated to your

Categories : C#

template template alias to a nested template?
At first consider using typename keyword to state that this is a nested type no matter if one is a type (e.g. struct, class, etc), template type, typedef or alias. Alias specification requires you to use a type-id to specify a previously defined type. In this particular case correct using of type-id will look like this: template< template<typename> class F, class T> using neg_v2 = typename neg_f<F>::template map<T>; // or struct foo {}; template< template<typename> class F> using neg_v1 = typename neg_f<F>::template map<foo>; What you try to do originally is to use template-name neg_f<F>::mapas a type-id. This is not correct. Probably you want to deduce somehow the T parameter from F to be used at template map<T> but this

Categories : C++

Defining array of classes with sub classes
your MNEMONIC macro takes 2 arguments, yet you are providing 9. You probably intended to write: MNEMONIC(INC, { OPCODE(INC_AX, 0, {OPERAND(REGISTER_AX, 4)}), OPCODE(INC_CX, 0, {OPERAND(REGISTER_CX, 4)}), // etc.. } ) // etc Note that the curly braces in your opcode macro initialize the struct, while the extra braces in the code above are used to initialize the arrays. Edit: note that the code above still does not work, since the preprocessor will still see the commas as argument delimiters.

Categories : C++

When to use inner classes in Java for helper classes
Yes, it makes perfect sense to make it an inner class. If no other classes need it, make it private. If it doesn't require exclusive access to the members of the outer class, make it a static nested class because then it will require less memory space. Check out the recommendation from the official tutorial - Use a non-static nested class (or inner class) if you require access to an enclosing instance's non-public fields and methods. Use a static nested class if you don't require this access.

Categories : Java

What are Gateway classes and Framework Classes
I'm not sure if the terms you used are formal terms. The way I understand it is something like: Gateway classes - The classes that conduct your API, then entry points to your application. For example, you said that your project is a webapp, so your controller class, your servlets, are the gateway classes. Those are the classes that allow to interact and start flows of your app. Framework classes - The classes that build your app. After starting a flow through your gateway classes, some logic starts to run. This logic probably consists various classes such as DAOs, Runnable, Utils and other classes that are part of the logic. Also, it consists of model classes - the classes that hold your data. All of these are you're framework classes.

Categories : Java



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