w3hello.com logo
Home PHP C# C++ Android Java Javascript Python IOS SQL HTML Categories
Looping through the derived classes by referencing the base class in C++
You were on the right way, there were just little things to fix : Add a getter to the base class (Car); Change the vector type (to a vector<Car*>); Replace a.b by a->b when needed; Fix missing semi-colon after classes definitions. And here you go : #include <iostream> #include <vector> using namespace std; class Car { public: virtual ~Car (); void addColor(string c) { color = c; } string getColor () { return color; } private: string color; }; class Honda:public Car {}; class Toyota:public Car {}; int main() { vector<Car*> v; Honda car1; car1.addColor("green"); Toyota car2; car2.addColor("blue"); v.push_back(&car1); v.push_back(&car2); for (int i =

Categories : C++

Java Referencing Abstract Classes
just replace public class MyFirstQuest { name = "A quest"; id = 0; } by public class MyFirstQuest extends Quest{ public MyFirstQuest(){ name = "A quest"; id = 0; } } and there are some tips : use private variables and use getters like this public String getName(){return name;} remove the abstract of the method getPrerequisite

Categories : Java

Actionscript 3.0: Referencing functions from other classes
Public functions are only accessible on an instance that's already instantiated in memory. For example: var redBall:Ball = new Ball(); redBall.bounce(); This works, because I have an instance of Ball in memory, and a valid path to the method contained in it. If I omitted the instance, It would throw an error. If you want to call a method on a class without instantiating that class, you need a static method. package { public class Ball { public static bounce():String { return "boing!" } } } Now that the method is static, I can call the method on the class directly, rather than an instance of that class. Ball.bounce() // traces "boing!"

Categories : Actionscript

Mutually referencing classes and subclassing in Objective-C
This is a question that's easier than it looks, thanks to recent advances in the language. This is exactly the reason that class extensions exist, and to illustrate my point, I've defined an interface and a pseudo-method file. // CFIAAAsAndBBBs.h @class AAA; @class BBB; @interface AAA : NSObject @property (readonly,nonatomic,copy) BBB* bbb; @end @interface BBB : NSObject @property (readonly,nonatomic,copy) AAA* aaa; @end @interface MutableAAA : AAA @end @interface MutableBBB : BBB @end First, notice the changes I've made to the header. Instead of having readwrite properties exposed in the header, you move them to the implementation file. If you need to expose them to any other object, just declare another set of readwrite properties using the superclasses you've defi

Categories : Objective C

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++

Problem to plot 3D surface with R‏
Try this to see why I don't think this data is well suited for wireframe: cloud(Z~X+Y, data=FI02, xlab="X", ylab="Y", main="Surface elevation", type="l", screen=list(z=-60, x=-60))

Categories : R

Self-referencing many-to-many relationship EF code first
You should include Friends in the results. You can do this by adding Include("Friends")at Server Side API. [HttpGet] public IQueryable<Person> Persons() { return _contextProvider.Persons.Include("Friends"); } If you don't want to return always the Friendsreference, you can create another method in the API such as PersonsWithFriends as suggested in here (Specialized query actions).

Categories : Entity Framework

code first self referencing foreign key
You need to handle 2 way mapping: modelBuilder.Entity<User>() .HasMany(a => a.SubsetUsers) .WithRequired(a => a.ParentUser) .HasForeignKey(a => a.ParentUserName); modelBuilder.Entity<User>() .HasOptional(a => a.ParentUser) .WithMany(a=> a.SubsetUsers);

Categories : Wpf

Set up self referencing class
There's a problem in the setter of the Children property: if (this.PropertyChanging != null) PropertyChanging(this, new PropertyChangingEventArgs("Children")); this.children.Assign(value); if (this.PropertyChanged != null) PropertyChanged(this, new PropertyChangedEventArgs("Children")); You're calling this.children.Assign even though children might not be initialized. Use the same check as your getter to prevent this issue: if( children == null) children = new EntitySet<DirectoryItem >(); this.children.Assign(value);

Categories : C#

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

Referencing a class that inherits from another class
Main _main = new Main() it underlines new Main() saying that it doesn't contain a constructor that takes 0 arguments. It's telling you exactly what the problem is. There isn't a public constructor on Main that takes zero arguments. You need to do one of the following: Add a public constructor that takes zero arguments: public Main() { }. Invoke a different constructor that is public on the Main class: if the signature is public Main(object o) then you'd say Main _main = new Main(o) where o is some object. Let's look at an example: class Foo { public Foo() { } } This class has a public constructor with zero arguments. Therefore, I can construct instances via Foo foo = new Foo(); Let's look at another example: class Bar { public Bar(int value) { } } This class doe

Categories : C#

Referencing a static class from within another class
It should work as you've written it above: class Site { public static $url; } class Something { public function __construct() { echo Site::$url; } } Site::$url = 'whatever'; new Something(); // prints 'whatever' If that's not working, it's likely because the classes are being declared in two different namespaces.

Categories : PHP

Issue referencing images in code
If you change all references $("images.homeannual") to $('img.homeannual') The code actually works. Obviously under the condition that the images you want to process has the class homeannual, eg <img src="1.gif" class="homeannual">

Categories : Javascript

CSS Class Referencing in HTML
Move <link rel="stylesheet" href="CSS/Styles.css"/> to the head or before the <div id="navigation">. Like this: <head> <link rel="stylesheet" href="CSS/Styles.css"/> </head> Or: <link rel="stylesheet" href="CSS/Styles.css"/> <div id="navigation"> <ul class="top-level"> But it's better to move it to the head as it's easier to manage. Also check if the path CSS/Styles.css is correct.

Categories : HTML

referencing class from string value and query
If you want to access various databases with all having the same schema ( from your code it seems like it is), then it should be very simple. Make a derived class from SQLiteOpenHelper. When you create this object, pass the database name. The other parts of the application do not need to know what database it is using. Also make sure to make this class a singleton. So you can switch to other database easily by closing the currently used one and then opening the new one. When you will be calling getWritableDatabase() for database operations from any place, it will return the correct db handle.

Categories : Android

C++, a number of classes derive from a class, all the derived classes use a class derived from something else but their base uses that clase's base
That sounds like the standard "abstract factory"-type situation: struct AbstractGadget { virtual ~AbstractGadget() {} }; struct AbstractWidget { virtual ~AbstractWidget() {} }; struct AbstractThingy { virtual ~AbstractThingy() {} }; struct AbstractFactory { virtual ~AbstractFactory() {} virtual std::unique_ptr<AbstractGadget> make_gadget() = 0; virtual std::unique_ptr<AbstractGadget> make_widget() = 0; virtual std::unique_ptr<AbstractGadget> make_thingy() = 0; }; Usage: struct Gadget1 : AbstractGadget { /* ... */ }; struct Widget1 : AbstractWidget { /* ... */ }; struct Thingy1 : AbstractThingy { /* ... */ }; struct Factory1 : AbstractFactory { virtual std::unique_ptr<AbstractGadget> make_gadget() { return { new Gadget1; } }

Categories : C++

How to call an object something other than the name of its class when referencing it with another controller
Change the scaffold room to this: rails generate scaffold Room name:string owner_id:integer and change the app/models/room.rb: class Room < ActiveRecord::Base belongs_to :owner , :class_name => 'Player' has_many :players #your code end then you can use the reference, remember set up the owner_id when creating the room.

Categories : Ruby On Rails

Referencing page/control from ITemplate class
Use the sender argument to get your TextBox, then you are already there since every control has a Page property. void txt_TextChanged(object sender, EventArgs e) { Control txt = (Control) sender; Page page = txt.Page; }

Categories : C#

kruskal.test shows "All group levels must be finite" error. What is the problem?
It should work if you run data$Grp <- as.factor(data$Grp) Then (as before): kruskal.test(data$Val, data$Grp) This is because Grp is a character not a factor and is.finite applied to an object of character class is always false (see ?is.finite).

Categories : R

Difference between using a method in a class to return a value and referencing the exact value itself
If guiWait is a public boolean, there is no point in having a "getter" method for it. If it were private or protected, then it'd be a different story. The private-getter method is more flexible because you can change the implementation of the "getting" of that variable, and add checks or whatever inside the method. Private getters/setters also make things clearer and establish which things should be seen by other classes and which are only meant to be used inside a single class they are apart of. If you find you do need a getter for a specific member variable (need some kind of verification or checking), which is very common, then it would be inconsistent to do it just for that variable.

Categories : Java

Referencing nested class to get JQuery click to work
It's cause you have no DIV .content as your .next() element. Try with: jQuery(this).closest('.container').next("div").find('.content').slideToggle(500); You have to take a more carefully look at all the DOM traversal methods that are offered by jQuery: http://api.jquery.com BTW, instead of rewriting all over the place the word jQuery go with: jQuery(function( $ ) { $(".content").hide(); $(".da-slider .da-slide .da-link").click(function() { $(this).closest('.container').next("div").find('.content').slideToggle(500); }); });

Categories : Jquery

Referencing a previous used Class in a Intellij Live Template
I don' think you easily make a backward reference, but you can try someting like this: $CLASS_NAME$ $END$ = ($CLASS_NAME$) findViewById(R.id.$END$); or $CLASS_NAME$ $VAR$ = ($CLASS_NAME$) findViewById(R.id.$END$);

Categories : Intellij Idea

Referencing through super class/interface reference - Java
How would it work when both extends and implements are involved with a class ? Assuming that is your question. The extends keyword is for extending a superclass. The implements is for implementing an interface The difference between an interface and a superclass is that in an interface you cannot specify an specific implementation of the whole (only its "interface"- Interfaces cannot be instantiated, but rather are implemented).So this means you can only specify methods you want to incorperate, but not implement them on your project in the same sense.

Categories : Java

Hibernate: table per concrete class mapping & referencing
There is quite much nothing to configure, just creating relationship to Payment, for example: @OneToOne private Payment payment; and then assigning value to it and persisting them. No additional columns are used to find out type of the Payment. To determine type of the Payment Hibernate Makes union of results of query to CashPayment results of query to CreditCardPayment table. Those select statements contain additional item in select list that denotes type. Outer select fetches values from nested query (result of union). Additional attribute determines which concrete class will be used when creating instances of Payment.

Categories : Hibernate

Why is there a java.lang.NullPointerException when referencing Image from a different class?
Lets look at that "line": if (by >= bricks[0].y && by <= bricks[0].y + bricks[0].img.getHeight(null) && bx >= bricks[0].x && bx <= bricks[0].x + bricks[0].img.getWidth(null)) { Assuming that bx, by, and the x and y fields are all primitive types (e.g. int), then here's a list of things that could result in an NPE: the bricks variable is null the zeroth element of bricks is null the value of bricks[0].img is null If bx, by, x and/or y is a wrapper type, then one of those could be null. That would lead to an NPE when unboxing the value. It is not caused by passing null to the getHeight or getWidth methods, because 1) I believe that is valid and 2) if it wasn't then the NPE would be thrown in a different place to what you

Categories : Java

MVC Code First referencing existing table getting error {"Invalid object name 'dbo.TableNames'."}
Create the model class for Market. use a table annotation (on the model) [Table("Market")] public class Market { } You can alternatively remove pluralization from the whole database (in the context file) with: protected override void OnModelCreating(ModelBuilder modelBuilder) { modelBuilder.Conventions.Remove<PluralizingTableNameConvention>(); }

Categories : Asp Net Mvc

php referencing undefined class properties doesn't throw errors
its not an error. php would get mad if you tried to call an undefined method, but in this case, php is happy to take that statement as a declaration. <?php class test{ private $s; function test(){ $this->d="test"; } } $c=new test(); echo $c->d; //"test" ?>

Categories : PHP

Trouble referencing class object inside a nested function
You need to scope the inner functions: class CoffeeScriptClass constructor: (@foo) -> _sampleFunction: -> $.each BigArray, (index, NestedArray) => // keep parent scope $.each NestedArray, (index, widget) => // keep parent scope ## I'd like @foo to reference the constructor value widget = @foo return return return Here is the compiled JS showing why this works: var CoffeeScriptClass; CoffeeScriptClass = (function() { function CoffeeScriptClass(foo) { this.foo = foo; } CoffeeScriptClass.prototype._sampleFunction = function() { var _this = this; // reference to the class is maintained $.each(BigArray, function(index, NestedArray) { $.each(NestedArray, function(index, widget) { widget

Categories : Javascript

Create a Django model with referencing Models in Manager class
How would I go about creating a "Company" with a default "Showroom? Override the save method of model Company or register a post save signal on model Company. Can I use the unsaved company to create my showroom? No. Updated: class Company(models.Model): name = models.CharField(max_length=100) email = models.EmailField() def save(*args, **kwargs): super(Company, self).save(*args, **kwargs) self.showroom__set.create(name=self.name) Updated by Berdus: class Company(models.Model): name = models.CharField(max_length=100) email = models.EmailField() def save(self, *args, **kwargs): is_first_save = self.pk is None super(Company, self).save(*args, **kwargs) if is_first_save: self.showroom_set.create(name=self.name) Note the se

Categories : Python

Android NoClassDefFound when referencing class from external libraries (IntelliJ IDEA 12)
Try to do this : Android, IntelliJ Idea, changing module type I had the same error "Could not find class XXX from referenced method XXX" with Intellij, involving an Android Test Module and a test which could not find the Activity class anywhere. I set inside the Project Structure the main Module's Facet Android to Library Module (checkbox) and it worked... Let us know

Categories : Android

Will a UITableViewController Garbage Collect if it instances a nested class referencing itself in a variable?
It will be released. The reason is that the "Source" property is a weak property in Objective-C, which means that the assignment there does not call retain on the object, it merely keeps a reference to it. Strong cycles that would prevent GC from happening only happen if Objective-C calls retain on the passed object. The following example shows how the data is eventually released, you have to first drill down a bunch of times, then drill back up. public class MyViewController : UITableViewController { public override void ViewDidLoad() { base.ViewDidLoad(); this.TableView.Source = new ViewSource(this); } public class ViewSource : UITableViewSource { public override int RowsInSection (UITableView tableview, int section) {

Categories : C#

Java - Class hierarchy, child classes containing different object types, and handling them from another class
From your description it seems to me that you have two places where the variety of tasks is visible: The task hierarchy itself and the response processing in the main thread. That means that adding a new task might require changes in those two places, which makes your code less flexible. I wonder if you could encapsulate this variety in one place. One idea is to use Strategy Pattern: A strategy in this case would define the processing logic, which depends on the whole response collection. A specific Task class would just hold a reference to the strategy. That would require also creating an interface like ITask with one method, getProcessingStrategy(). In your case, the strategy interface would need to be able to accommodate your complex processing scenarios (e.g. execute(Collection<IRe

Categories : Java

Scope of classes inside of functions and classes inside of a class in python
The thing to realize is that the class statement just creates a variable whose value is a class. The way the resulting class's scope works is the same the way a variable's scope would work if you just did a normal variable assignment like x = 2. Any variables you create inside a function are local to that function unless you specify otherwise. So using a class statement inside a function just creates a local variable whose value is a class. It can't be accessed from outside the function. In other words, this: def foo(): class A(object): pass is not really different from this: def foo(): A = 2 In both cases you create a local variable A inside the function. In one case its value is a class and in the other its value is an integer, but in both cases it's a local va

Categories : Python

Nest Classes using Abstract class? (As well as protect/hide a class)?
Answer #1: Instead of ... //Member variables... private string _emulation = ""; private string _application = ""; private string _database = ""; //Get/Set properties... public string Emulation { get {return _emulation;} set {_emulation = value;} } public string Application { get {return _application;} set {_application = value;} } public string Database { get {return _database;} set {_database = value;} } Your properties can be expressed this way instead (it is equivalent, except for the initialization to "", which can be done if needed in a constructor instead): public string Emulation { get; set; } public string Application { get; set; } public string Database { get; set; } Answer 2/3: Abstractness and inner classes are not used to limit the visibility of classes to

Categories : C#

Must of referencing of third-party libs which used in a class library which is referenced by Windows Store App project
If you use classes from your class library which use SharpDX classes, then compiler of main assembly must know what this classes are, so it needs reference to SharpDX. It's common .net behavior.

Categories : Visual Studio 2012

Self referencing entity & insert order - using Entity Framework Code First
I have had the same error with foreign keys using EF. It may not be related however the answer that was provided helped me understand why I was getting the error. Issue with EF and Foreign keys In summary of Slauma's answer I was clearing the vertical navigation values before my EF insert. This caused an issue, all-though it is a different issue it may help. Potential Solution If you where to all your AssetSession object to your Asset object and then do one root add that should allow EF to insert both correctly. Note: To do this you may need to generate your GUID in advance of inserting your objects.

Categories : C#

Abstract base class for derived classes with functions that have a return type of the derived class
When a virtual function returns a pointer or reference to a class, a class which inherits from the base class and overrides the function is allowed to change the return type to a pointer or reference to a class which is derived from the original return type. You can't return base by value as it is abstract so you can't actually create one by itself. http://en.wikipedia.org/wiki/Covariant_return_type When using virtual functions and base classes, you usually have to use dynamic allocation to create your objects. I suggest you look into smart pointers to help manage the memory.

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

jquery code for many classes, map-1, map-2
Do like this $('.map-1 .map-2 .map-3') and it should work. But it is advisable to use unique ID such as map1, map2, map3. In this case you can use wild card selector of jquery. For ex: $("[id^=map]"), now this will work for all the ID's having 'map'

Categories : Jquery



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