Calling specific class functions in a list of multiple class-types |
You could investigate the OfType method, it filters based on type:
using System.Linq;
...
foreach(var door in tileList.OfType<Door>())
{
door.Toggle();
}
|
Class creating multiple objects of another class at the same memory location (C++) |
This line:
std::cout << &myFSM.getTopNode();
probably prints the address of a temporary object, not the actual object in
the vector. This will be true if you're not returning by reference but
rather by value.
So it's not weird if the temporary happens to be created at the same
location each time, since after the temporary dies, its location in memory
is free to be used again later.
In order to get the actual object rather than a copy of it, getTopNode()
needs to do:
Node& FSM::getTopNode()
{
if (nodeList.empty()) {
// Up to you how to handle this error.
}
return nodeList.back();
}
Of course, if your current getTopNode() implementation actually already
returns a pointer:
Node* FSM::getTopNode()
then your problem is that you're printing out the ad
|
PHP: How to control multiple instances of Class in MVC (where multiple modules load) without Singleton |
How about an inversion of control system? You could make a global IOC
object that has instructions for creating an object, but that also has a
registry that contains references to already created objects. In the
registration portion of the module for each item that you want to behave
"singletonny", you simply check to see if it's already been instantiated.
The only other option I can think of is that since you aren't looking to
construct anything, make it a static class that you can't instantiate and
access the class statically (Calendar::printSomeFunction).
I am not, however, opposed to the singleton pattern, for what it's worth,
when it's used correctly. I just choose more elegant solutions such as #1
here, because it is very flexible. You don't however have much control over
whether or
|
Javascript multiple class each function get selected class name |
Within your iterator function, this will be the matching DOM element. That
element has a className property with a space-delimited list of the classes
on the element. There may well be more than one, unless you know in your
markup that there will only be one.
If only one, just use this.className directly.
var newclass = this.className;
If more than one, you may find jQuery's hasClass function useful:
var $this = $(this);
if ($this.hasClass('effect1')) {
// ...
}
else if ($this.hasClass('effect2') {
// ...
}
// ...
But, if you want to do different things depending on which class the
element matched, it probably makes more sense to break up your query. Then
you may not even need each, if you're trying to do something to all
elements matching a given class.
For example:
jQu
|
Is it possible to use css wildcard class selector where there are multiple class values? |
You were using an incorrect selector - a [class] is all anchors with a
class as a descendant.
Basically, any element descending from an <a>, which starts with or
contains the class icon- will be targeted.
What you want is to select all anchors starting with or containing that
class themselves - a[class]:
a[class^="icon-"], a[class*=" icon-"] {
text-decoration: none;
color: #1BA1E2;
}
jsFiddle example here.
|
Having multiple validation functions in a class with multiple actions |
Create validateXxx methods where Xxx is the name of the related action
method.
(Whether or not this is the best option depends on the particular
validations you need.)
|
Need to set multiple onclicklisteners for multiple gridviews in single class |
let the IDE create the function itself.
Look like you wrote it by yourself as I see you don't have the @Override
annotation.
try delete your onItemClick function and let the eclipse/intellij/whatever
it is to do it for you.
you should see it with the annotation:
@Override
public void onItemClick(AdapterView<?> adapterView, View view,
int i, long l) {
}
If this still not working (can't see why not) try it anonymously:
g.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> adapterView, View
view, int i, long l) {
// your logic here...
}
});
For the second question, seems that the system using lots of memory when
you're loading and sets image resource. I would suggest
|
How to include multiple class files and .Jar files in class path which exist in sub folders in linux? |
Use below command:
export CLASSPATH="$CLASSPATH:xyz.jar**:**path_to_abc.jar.jar"
You basically have to append to the classpath, all the new entries that you
want. To do so, just make use of ':' in linux and ';' in windows.
|
Multiple Interfaces to a Class in C++ |
If you define ObjectB as a ClassBInterface2 it won't be possible to convert
it to ClassBInterface1 at runtime because it's internal structure won't be
known.
Your way is the best one to do it but you can do a little modification. You
don't need to do a explicit cast from ClassB to ClassBInterface1 while
calling ObjectC.Bar because the compiler will do it for you.
If class B is defined as follows:
ClassB : public ClassBInterface1, ClassBInterface2
{
/*Class methods and attributes*/
}
you can just do the following while calling the Bar function on the ObjectC
(assuming objectB is defined as ClassB)
ObjectC.Bar(ObjectB);
|
Multiple Instances of JS Class |
I never look at the code of kinetic group. But this problem could happen if
the code uses closure to create private variables like this:
Kinetic.Group = function(){
var setX, getX;
(function() {
var X = 0;
getX = function(){
return X ;
};
setX = function(v){
X = v;
};
})();
this.setX = setX;
this.getX = getX;
}
When you declare Enemy.prototype = new Kinetic.Group();, there is only 1
Kinetic.Group created. When you call this.setX(position.posX); inside
function Enemy(position, rotation), because this function does not exist in
the current instance, it will look up that function in the prototype
property (the same Kinetic.Group for all your Enemy). All your instances
created by the constructor function share the
|
Multiple listeners in one class |
This may be overkill for your use case, but for notifying classes about
events I use an event bus (specifically
https://github.com/greenrobot/EventBus).
This allows you to simply post a message and every class that has
registered to receive that type of message gets it. Very simple to use, and
pretty small as far as libraries go.
|
Multiple Comparable in a class |
Assuming Comparators are not working(which i'm curious as to how they're
not working), or you simply don't want to use one, you could write a
wrapper class that has an instance of your original class as data.
ex.
public class HorsesWrapper implements Comparable<HorsesWrapper>
{
private Horses horses;
public int compareTo(HorsesWrapper other)
{
// your sort criteria based on the Horse member.
}
}
|
is it possible to combine multiple ng-class |
Instead of doing an Angular version you could just create a css classes of
.upload .checkbox etc.. that map to the icon-*
<li ng-repeat="el in elm.required">
<i tooltip="{{el.name}}" class="{{el.type}}"
ng-class="{'muted':!el.completed}" ></i>
</li>
Example on jsfiddle
|
Multiple Jbutton and ActionListener using inner class |
Each time you click labelButton it is firing a repaint event for
MyDrawPanel.
This causes the color to be randomly generated again, changing the color of
MyDrawPanel.
I suggest fixing this by calling a method from ColorListener on MyDrawPanel
which changes its color. This will keep the panel from changing color every
repaint.
And here's precisely how to do it:
class ColorListener implements ActionListener{
MyDrawPanel colorPanel;
public ColorListener(MyDrawPanel panel){
this.colorPanel = panel;
}
public void actionPerformed(ActionEvent event2) {
colorPanel.generateRandomColor();
frame.repaint();
}
}
public class MyDrawPanel extends JPanel{
GradientPaint gradient;
public MyDrawPanel(){
generateRandomColor();
}
publi
|
Using Multiple Namespaces to Describe a Class |
A class can not belong to two different namespaces.
If you want to refer to a class of the Engine or Core namespaces without
explicitly writing the namespace each time you reference a type of those
namespaces, just use using at the beginning of the file. The using
directive allows the use of types in a namespace so that you do not have to
qualify the use of a type in that namespace:
using Engine;
or
using Core;
Check the documentation: using Directive
|
Strategy to have multiple validations for the 'same' class |
It seems to me that you should separate the concern of holding the data
from validating the data - as the latter is context-specific. You may well
want to put some "core" validation into Address, but then separate out the
other validators into ContactAddressValidator and VendorAddressValidator
classes (possibly implementing some sort of Validator<T> interface).
This is the same approach as you take to sort the same type in different
ways, implementing Comparator<T> multiple times for the same T, but
in different classes.
|
Is there a way to get the Dex Loader in Android to allow multiple of a class? |
One options is to exclude the library project from the build in one of the
projects.
Library project dependencies are stored in the Android Private Libraries
classpath container in Eclipse/ADT.
In the latest ADT (and probably in older versions to), you can opt to not
export this classpath container.
Imagine the scenario were you have a project depending on
the Google Play Services Library.
android-maps-utils (A google maps extension library project that also
depends on Google Play Services)
In this case you will run into the following error at package/deploy time :
Unable to execute dex: Multiple dex files define
Lcom/google/android/gms/R$attr;
Conversion to Dalvik format failed: Unable to execute dex: Multiple dex
files define Lcom/google/android/gms/R$attr;
If you configure t
|
Multiple return from a class function |
You cannot return multiple times in a function.
If you need to return more than one value you can do something like:
return array('author'=>$this->author,
'bookName'=>$this->bookName);
And use it like this:
$res = $obj->getproperty();
echo "Author is ".$res['author'];
echo "Book is ".$res['bookName'];
You may want to change this depending on what the method is for/ how it
will be used.
|
Create multiple instances of a class |
Let's say you have a class called enemy in your game. For the sake of
brevity, I won't define the functions explicitly and will just use pass
statements as placeholders.
class Enemy:
def __init__(self):
pass
def update(self):
pass
def draw(self, display_surface):
pass
To create multiple enemies you just need to do create a list of enemies
where you will store all your reference to your currently active enemy
objects.
enemies = []
To add a single enemy, you just append a call of the constructor of enemy
to your list. You can do this as many times as you want.
enemies.append(Enemy())
As @monkey also mentioned in the comments, you can easily use list
comprehension to set your list of active enemies to multiple object
instances at once.
enemies =
|
Multiple accessor views on c++ class |
Choosing from the two options I'd choose the "friend" one, because it
doesn't need several additional lines of code, the logic is compacted (not
split in two separate classes) and because it fulfills your need.
A polymorphic solution could be however implemented to "hide" from the
plugin user the unneeded code.
So my solution could be a mixture from those two:
class A_base
{
friend class GlobalList;
public:
A_base(int v) : val(v) {}
int get() { return val; }
private:
int v;
void set(int v) { val = v; }
};
class A : public A_base
{
public:
A(int v) : A_base(v)
{
GlobalList::register(this);
}
};
and GlobalList must have a list of A * (or similar).
GlobalList have direct access of every A and A_base methods and fields,
public, protected and private ones
|
Multiple Enumerators for a Single C# Class |
Exposing two properties which return different enumerators is probably the
right way to go. Instead of your data structure implementing IEnumerable
itself (I'm guessing with that one), create two different IEnumerator
implementations, and have a propery exposed from the main class for each
one. Then the using code is straightforward:
foreach( var item in data.FastEnumerator )
{
....
foreach( var item in data.LexicalEnumerator )
{
....
|
Remove Element with multiple Class without ID |
Just remove the spaces in your selector:
$('.wijmo-wijsuperpanel-vbar-buttontop.ui-state-default.ui-corner-tr').remove();
With the spaces, it would select elements with ui-corner-tr class inside an
element with ui-state-default class inside an element with
wijmo-wijsuperpanel-vbar-buttontop class.
|
How to do Multiple setTimeout jQuery in a Class? |
In your setTimeout function, this is the window. Try this instead:
http://jsfiddle.net/uXVAs/
$(".content" ).each(function(){
var $this = $(this);
var time = $this.data("time");
setTimeout(function() {
$this.hide("slow");
}, time);
});
|
Clojure multiple constructors using gen-class |
Multiple Constructors
To have multiple constructors on the generated class you need all the
constructor parameters specified in the :constructors option of gen-class,
and the :init function should be multi-arity to match. Something like the
following:
(ns something-amazing
(:gen-class :init myconstructor
:state state
:constructors {[String] []
[String String] []}))
(defn -myconstructor
([^String p1] [[] {:name p1 :special false}])
([^String p1 ^String p2] [[] {:name p1 :special p2}]))
In this case, both constructors would call the same zero-parameter
super-type constructor, as specified by the empty vector values in the
:constructor hash-map.
Multiple States
State is generally a hash-map, so you don't need multiple state
|
Abstract Class with Multiple Levels |
obj must be declared as Last *, or at least Inter *
Inter *obj = new Last;
or
Last *obj = new Last;
If obj is just a CI *, the compiler can't see the parseData() method (your
object is instantiated as Last, but immediately implicitly converted to CI
and looses the benefit of the method).
I suggest that you look for what the notion of upcast means. (See also
about implicit conversion here or else)...
|
Can "with" keyword in VB.Net be used with multiple class objects |
No, that's not possible, you can nest them, but that's about it:
With something1
.property1 = value
With something2
.property2 = .property1 'something2.property2 =
something1.property1
End Width
End With
And it is really easy to get lost using this approach, especially if
there're common properties between objects, so it is not recommended.
|
Can a class observe multiple observables? |
you could also use instanceof operator to check which Observable class
called an update, eg:
@Override
public void update(Observable observable, Object data) {
if (observable instanceof ObservableClass1) {
//prcess ObservableCLass1 update here
} else if (observable instanceof ObservableClass2) {
//process ObservableClass update here
} else {
//some default action or error
}
}
|
OOP PHP extended class multiple includes |
It depends on how parentClass.php is loaded.
Unless you use require_once or include_once the file will be included
multiple times, which in return will lead to a Fatal Error, as each class
may only be defined once.
If you are using an autoloader the file will only be included once, as it
will only load unknown classes.
|
Pass multiple files to another class |
A simple implementation would be to keep a counter outside loop and
increment it before appending it to output file name
int counter = 0;
for(File f:files){
String path = f.getName();
System.out.println("The Name of file is="+path);
counter++; //increment the counter
cc.createPdf("path" , "output"+counter, true); // append it to
output
System.out.println("the file is ="+output+".pdf");
System.out.println("after convert");
}
For more robustness, counter can be replaced by UUID generator, System time
in milliseconds etc
|
How to allow multiple views use the same controller class? |
listTableVC *secondViewController = (listTableVC *)[[navigationController
viewControllers] objectAtIndex:0];
Should be maybe:
listTableVC *secondViewController = (listTableVC *)[[navigationController
viewControllers] objectAtIndex:1];
?
|
Using single Class in multiple Activities |
If you store your WebSocketClient object in the Application class you would
not have to have Singleton. You could just get it from
getApplicationContext() method in activities and use its methods as they
are.
That being said, if you will implement Singleton, I would suggest using
INSTANCE variable in enum instead of getInstance() method. You can find
example at following url: What is the best approach for using an Enum as a
singleton in Java?
|
multiple definition in stl class header |
You want include guards around the header:
#ifndef RTPSOCKET_H
#define RTPSOCKET_H
// header contents go here
#endif
This will prevent the header contents from being included more than once
per source file, so you will not accidentally get multiple definitions.
UPDATE: Since you say you have include guards, then possible causes of the
error might be:
misspelling the include guard name, so it doesn't work
defining something with the same name in another header (or the source file
that includes it)
undefining the include guard name.
But without seeing code that reproduces the error, I can only guess what
might be wrong.
|
Add active class to multiple tab navigation |
You forget to add your code into document.ready
$(function(){
$('#myTab a').click(function (e) {
e.preventDefault()
$(this).tab('show')
});
$('#myTab2 a').click(function (e) {
e.preventDefault()
$(this).tab('show')
});
});
|
Multiple Inheritance and class Object |
It's not multiple inheritance it's multi level inheritance. Classes can
extend one other class, which can extend one other class, ..., which
ultimately extends Object:
A --> B --> C --> Object
Multiple inheritance would be
A ----> B
--> C
This means that when a method or a field is used inside A, it's looked up
in A, then in B, then in C, then in Object.
With multiple inheritance, it would have to be looked up in A, then in B
and C, and there could be a conflict because the same method or field could
exist in both superclasses.
|
Can we configure a service class with multiple DAO's..? |
If you need to inject several beans which implement the same interface into
your service - check this answer, it may be what you are looking for.
Simple approach would be:
interface DevService
{
void add(Device d);
String getName();
}
@Service("devServiceLocal")
class DevServiceLocalImpl implements DevService
{
void add(Device d) {...}
String getName() {return "local";}
}
class Controller
{
@Autowired
Collection<DevService> services;
void doSomethingWithService()
{
// TODO: Check type somehow
String servType = "local";
for(DevService s: services)
{
if(servType.equals(s.getName())
{
// Call service methods
break;
}
}
}
}
|
JApplet with multiple .class files |
This works:
<applet height="x" width="y"
archive="your-package.jar"
code="your-main-class.class">
your-main-class.class is the class which extends JApplet.
If there are problems, check if the applet jar can be downloaded via
browser.
Here's a link on how to properly create jar file:
http://docs.oracle.com/javase/tutorial/deployment/jar/build.html
|
WCF Service where a class implements multiple interfaces |
NOTE This solution won't work for the OP (original poster), but I'll leave
it here for future readers that may be looking at how to do this when
implementing a new service.
The only way I can think of to do that is to create an new interface that
inherits the other interfaces, like this:
public interface IMasterService : IService1, IService2, IService3
{
}
Then you can implement IMasterService in your service and only need a
single endpoint:
public class MainService : IMasterService
{
}
serviceHost.AddServiceEndpoint(typeof(IMasterService), binding, address1);
Now you have a single interface (IMasterService) that you can use with
ChannelFactory<T>:
ChannelFactory<ServiceLibrary.IMasterService> channelFactory = new
ChannelFactory<IMasterService>(binding, address
|
How to use One Class for Multiple Listview Item Clicks |
Well if your layout is same then you can use the same Activity, but then
the code might get complex.
Are the ListView items dynamically generated as in the case of Google Maps
Places, or are the options specifically decided by you beforehand? If the
case is the former then you have to fetch data from a database as you can't
code for all possiblities, and if it is the latter you can explicitly code
too.
After that on the next page if you use database, then fetch data from a
SQLite database, or if its the latter case use Intent.getExtra(data) for
each data and assign those values to the Textfields.
If I understood your question, this should work.
|
Java Applet/Multiple Class Login |
Let's start with, this is not how Applets are used, in for that fact, how
UI's are used...
You problem stems from the fact that you seem "think" you control the paint
process...
objectName.paint(null);
But you are passing a null value to the paint method. Apart from the fact
that you should never have a need to call paint directly, I'm not sure what
you expected paint to do...
public void paint(Graphics g){
g.drawLine(10, 20, 50, 60 );
}
g is null...
Firstly, forget about applets, seriously, UI's and Swing are complicated
enough with adding the complexity of applets to the problem.
Secondly, take a read through Creating a GUI with Swing...
Swing has it's own mechanisms for getting user input, so you can drop the
Scanner...
|
CKEditor multiple style class not working |
You need to go into the config.js and set
CKEDITOR.config.allowedContent = true;
This way you will stop the CKEditor from stripping off the classes from
your elements.
Which version of CKEditor are you using?
If the problem started happening when you updated CKEditor library to 4.1
then in the "Advanced options" section of CKEditor profile add this:
config.allowedContent = true;
If you still have problem with this please refer to the CKEditor API
Documentation which states everything that you will need about this.
|