Search Results

Search found 42993 results on 1720 pages for 'static method'.

Page 12/1720 | < Previous Page | 8 9 10 11 12 13 14 15 16 17 18 19  | Next Page >

  • Class Methods Inheritence

    - by Roman A. Taycher
    I was told that static methods in java didn't have Inheritance but when I try the following test package test1; public class Main { /** * @param args the command line arguments */ public static void main(String[] args) { TB.ttt(); TB.ttt2(); } } package test1; public class TA { static public Boolean ttt() { System.out.println("TestInheritenceA"); return true; } static public String test ="ClassA"; } package test1; public class TB extends TA{ static public void ttt2(){ System.out.println(test); } } it printed : TestInheritenceA ClassA so do java static methods (and fields have) inheritance (if you try to call a class method does it go down the inheritance chai looking for class methods). Was this ever not the case,are there any inheritance OO languages that are messed up like that for class methods?

    Read the article

  • Why are static classes considered “classes” and “reference types”?

    - by Timwi
    I’ve been pondering about the C# and CIL type system today and I’ve started to wonder why static classes are considered classes. There are many ways in which they are not really classes: A “normal” class can contain non-static members, a static class can’t. In this respect, a class is more similar to a struct than it is to a static class, and yet structs have a separate name. You can have a reference to an instance of a “normal” class, but not a static class (despite it being considered a “reference type”). In this respect, a class is more similar to an interface than it is to a static class, and yet interfaces have a separate name. The name of a static class can never be used in any place where a type name would normally fit: you can’t declare a variable of this type, you can’t use it as a base type, and you can’t use it as a generic type parameter. In this respect, static classes are somewhat more like namespaces. A “normal” class can implement interfaces. Once again, that makes classes more similar to structs than to static classes. A “normal” class can inherit from another class. It is also bizarre that static classes are considered to derive from System.Object. Although this allows them to “inherit” the static methods Equals and ReferenceEquals, the purpose of that inheritance is questionable as you would call those methods on object anyway. C# even allows you to specify that useless inheritance explicitly on static classes, but not on interfaces or structs, where the implicit derivation from object and System.ValueType, respectively, actually has a purpose. Regarding the subset-of-features argument: Static classes have a subset of the features of classes, but they also have a subset of the features of structs. All of the things that make a class distinct from the other kinds of type, do not seem to apply to static classes. Regarding the typeof argument: Making a static class into a new and different kind of type does not preclude it from being used in typeof. Given the sheer oddity of static classes, and the scarcity of similarities between them and “normal” classes, shouldn’t they have been made into a separate kind of type instead of a special kind of class?

    Read the article

  • Variables in static library are never initialized. Why?

    - by Coyote
    I have a bunch of variables that should be initialized then my game launches, but must of them are never initialized. Here is an example of the code: MyClass.h class MyClass : public BaseObject { DECLARE_CLASS_RTTI(MyClass, BaseObject); ... }; MyClass.cpp REGISTER_CLASS(MyClass) Where REGISTER_CLASS is a macro defined as follow #define REGISTER_CLASS(className)\ class __registryItem##className : public __registryItemBase {\ virtual className* Alloc(){ return NEW className(); }\ virtual BaseObject::RTTI& GetRTTI(){ return className::RTTI; }\ }\ \ const __registryItem##className __registeredItem##className(#className); and __registryItemBase looks like this: class __registryItemBase { __registryItemBase(const _string name):mName(name){ ClassRegistry::Register(this); } const _string mName; virtual BaseObject* Alloc() = 0; virtual BaseObject::RTTI& GetRTTI() = 0; } Now the code is similar to what I currently have and what I have works flawlessly, all the registered classes are registered to a ClassManager before main(...) is called. I'm able to instantiate and configure components from scripts and auto-register them to the right system etc... The problem arrises when I create a static library (currently for the iPhone, but I fear it will happen with android as well). In that case the code in the .cpp files is never registered. Why is the resulting code not executed when it is in the library while the same code in the program's binary is always executed? Bonus questions: For this to work in the static library, what should I do? Is there something I am missing? Do I need to pass a flag when building the lib? Should I create another structure and init all the __registeredItem##className using that structure?

    Read the article

  • Static method not called

    - by Smile
    I'm trying to call a static method (printABC()) in this class but it's not working. If I uncomment both of the lines marked T_T (1 and 2), it works! Why does it fail with only one of the lines? import java.util.Scanner; class pro0009 { static Scanner in = new Scanner(System.in); static int A,B,C; static void printABC(){ String ABC = in.nextLine(); ABC=ABC.replace("A"," "+A+" "); ABC=ABC.replace("B"," "+B+" "); ABC=ABC.replace("C"," "+C+" "); //System.out.print(ABC.substring(1)); System.out.print(ABC); } public static void main(String[] args){ int x = in.nextInt(); //1 int y = in.nextInt(); //2 int z = in.nextInt(); //3 if(x<y){//1<2 if(x<z){ //1<3 if(y<z){//x<y<z 2<3 //1<2<3 A=x; B=y; C=z; printABC();//T_T 1 System.out.println("Here"); //pro0009.printABC();//T_T 2 //System.out.println("Here2"); }else{ //x<z<y A=x; B=z; C=y; } }else{//z<x<y A=z; B=x; C=y; } }else{//y<x if(y<z){ if(x<z){//y<x<z A=y; B=x; C=z; }else{//y<z<x A=y; B=z; C=x; } }else{//z<y<x A=z; B=y; C=x; } } } }

    Read the article

  • Accessing Static Methods on a Generic class in c#

    - by mrlane
    Hello, I have the following situation in code, which I suspect may be a bit dodgey: I have a class: abstract class DataAccessBase<T> : IDataAccess where T : AnotherAbstractClass This class DataAccessBase also has a static factory method which creates instances of derived classes of itself using an enum value in a which statement to decide which derived type to create: static IDataAccess CreateInstance(TypeToCreateEnum) Now, the types derived from DataAccessBase<T> are themselves NOT generic, they specify a type for T: class PoLcZoneData : DataAccessBase<PoLcZone> // PoLcZone is derived from AnotherAbstractClass So far I am not sure if this is pushing the limits of good use of generics, but what I am really concerned about is how to access the static CreateInstance() method in the first place: The way I am doing this at the moment is to simply pass any type T where T : AnotherAbstractClass. In particular I am passing AnotherAbstractClass itself. This allows compilation just fine, but it does seem to me that passing any type to a generic class just to get at the statics is a bit dodgey. I have actually simplified the situation somewhat as DataAccessBase<T> is the lower level in the inheritance chain, but the static factory methods exists in a middle tier with classes such as PoLcZoneData being the most derived on the only level that is not generic. What are peoples thoughts on this arrangement?

    Read the article

  • How do I call a static bool method in main.m

    - by AaronG
    This is Objective-C, in Xcode for the iPhone. I have a method in main.m: int main(int argc, char *argv[]) { NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init]; //I want to call the method here// int retVal = UIApplicationMain(argc, argv, nil, nil); [pool release]; return retVal; } static BOOL do_it_all () { //code here// } How do I call the do_it_all method from main.m?

    Read the article

  • Thread-safe initialization of function-local static const objects

    - by sbi
    This question made me question a practice I had been following for years. For thread-safe initialization of function-local static const objects I protect the actual construction of the object, but not the initialization of the function-local reference referring to it. Something like this: namspace { const some_type& create_const_thingy() { lock my_lock(some_mutex); static const some_type the_const_thingy; return the_const_thingy; } } void use_const_thingy() { static const some_type& the_const_thingy = create_const_thingy(); // use the_const_thingy } The idea is that locking takes time, and if the reference is overwritten by several threads, it won't matter. I'd be interested if this is safe enough in practice? safe according to The Rules? (I know, the current standard doesn't even know what "concurrency" is, but what about trampling over an already initialized reference? And do other standards, like POSIX, have something to say that's relevant to this?) For the inquiring minds: Many such function-local static const objects I used are maps which are initialized from const arrays upon first use and used for lookup. For example, I have a few XML parsers where tag name strings are mapped to enum values, so I could later switch over the tags enum values.

    Read the article

  • How is method group overload resolution different to method call overload resolution?

    - by thecoop
    The following code doesn't compile (error CS0123: No overload for 'System.Convert.ToString(object)' matches delegate 'System.Converter<T,string>'): class A<T> { void Method(T obj) { Converter<T, string> toString = Convert.ToString; } } however, this does: class A<T> { void Method(T obj) { Converter<T, string> toString = o => Convert.ToString(o); } } intellisense gives o as a T, and the Convert.ToString call as using Convert.ToString(object). In c# 3.5, delegates can be created from co/contra-variant methods, so the ToString(object) method can be used as a Converter<T, string>, as T is always guarenteed to be an object. So, the first example (method group overload resolution) should be finding the only applicable method string Convert.ToString(object o), the same as the method call overload resolution. Why is the method group & method call overload resolution producing different results?

    Read the article

  • Apply [ThreadStatic] attribute to a method in external assembly

    - by Sen Jacob
    Can I use an external assembly's static method like [ThreadStatic] method? Here is my situation. The assembly class (which I do not have access to its source) has this structure public class RegistrationManager() { private RegistrationManager() {} public static void RegisterConfiguration(int ID) {} public static object DoWork() {} public static void UnregisterConfiguration(int ID) {} } Once registered, I cannot call the DoWork() with a different ID without unregistering the previously registered one. Actually I want to call the DoWork() method with different IDs simultaneously with multi-threading. If the RegisterConfiguration(int ID) method was [ThreadStatic], I could have call it in different threads without problems with calls, right? So, can I apply the [ThreadStatic] attribute to this method or is there any other way I can call the two static methods same time without waiting for other thread to unregister it? If I check it like the following, it should work. for(int i=0; i < 10; i++) { new Thread(new ThreadStart(() => Checker(i))).Start(); } public string Checker(int i) { public static void RegisterConfiguration(i); // Now i cannot register second time public static object DoWork(i); Thread.Sleep(5000); // DoWork() may take a little while to complete before unregistered public static void UnregisterConfiguration(i); }

    Read the article

  • Ruby: Alter class static method in a code block

    - by Phuong Nguy?n
    Given the Thread class with it current method. Now inside a test, I want to do this: def test_alter_current_thread Thread.current = a_stubbed_method # do something that involve the work of Thread.current Thread.current = default_thread_current end Basically, I want to alter the method of a class inside a test method and recover it after that. I know it sound complex for another language, like Java & C# (in Java, only powerful mock framework can do it). But it's ruby and I hope such nasty stuff would be available

    Read the article

  • Categories in static library for iPhone device 3.0

    - by Nick
    I have categories in my static library. Any application developer should set -ObjC flag to "Other Linker Flags" to use my static library properly. It works fine for iPhone device/iPhone Simulator 2.x and iPhone Simulator 3.0. But it crashes for iPhone device 3.0. As written in this article it is new linker bug. They suggest to use one more linker flag: -all_load. But when I add this flag, build fails too, because there are duplicate symbols. How to use categories in static libraries for iPhone device 3.0? Any suggestions?

    Read the article

  • DLL export of a static function

    - by Begbie00
    Hi all - I have the following static function: static inline HandVal StdDeck_StdRules_EVAL_N( StdDeck_CardMask cards, int n_cards ) Can I export this function in a DLL? If so, how? Thanks, Mike Background information: I'm doing this because the original source code came with a VS project designed to compile as a static (.lib) library. In order to use ctypes/Python, I'm converting the project to a DLL. I started a VS project as a DLL and imported the original source code. The project builds into a DLL, but none of the functions (including functions such as the one listed above) are exported (as confirmed by both the absence of dllexport in the source code and tools such as DLL Export Viewer). I tried to follow the general advice here (create an exportable wrapper function within the header) to no avail...functions still don't appear to be exported.

    Read the article

  • accessing a static property via COM

    - by joreg
    is it possible to access a static property of a COM object without creating an instance of the object? my situation is this: i have an unmanaged application (written in delphi). this application exposes a COM-based plugininterface. until now i only wrote managed plugins in c#. plugins provide their info (name, author, ..) via a static property that returns an instance of PluginInfo (which implements IPluginInfo). this static property i can access on the managed plugins using http://managedvcl.com. now i want to write unmanaged plugins on the same interface. i can load them using: plug := CreateComObject(TGuid) as IMyPlugInterface; and they run, but i don't know how to read out their PluginInfo. so the question again is: is there another way than implementing IPluginInfo in the plugin-class and only accessing the info after i have created an instance of the plugin?

    Read the article

  • .NET: will Random.Random operate differently inside a static method

    - by Craig Johnston
    I am having difficulty with the following code which is inside a static method of a non-static class. int iRand; int rand; rand = new Random((int)DateTime.Now.Ticks); iRand = rand.Next(50000); The iRand number, along with some other values, are being inserted into a new row of an Access MDB table via OLEDB. The iRand number is being inserted into a field that is part of the primary key, and the insert attempt is throwing the following exception even though the iRand number is supposed to be random: System.Data.OleDb.OleDbException: The changes you requested to the table were not successful because they would create duplicate values in the index, primary key, or relationship. Change the data in the field or fields that contain duplicate data, remove the index, or redefine the index to permit duplicate entries and try again. Could the fact the method is static be making the iRand number stay the same, for some reason?

    Read the article

  • Java: startingPath as "public static final" exception

    - by HH
    [Updated] Thanks to polygenelubricants's reply, the real problem is the exception from the method getCanonicalPath() because I cannot include try-catch-loop there. $ cat StartingPath.java import java.util.*; import java.io.*; public class StartingPath { public static final String startingPath = (new File(".")).getCanonicalPath(); public static void main(String[] args){ System.out.println(startingPath); } } $ javac StartingPath.java StartingPath.java:5: unreported exception java.io.IOException; must be caught or declared to be thrown public static final String startingPath = (new File(".")).getCanonicalPath(); ^ 1 error

    Read the article

  • Returning in a static initializer

    - by Martijn Courteaux
    Hello, This isn't valid code: public class MyClass { private static boolean yesNo = false; static { if (yesNo) { System.out.println("Yes"); return; // The return statement is the problem } System.exit(0); } } This is a stupid example, but in a static class constructor we can't return;. Why? Are there good reasons for this? Does someone know something more about this? So the reason why I should do return is to end constructing there. Thanks

    Read the article

  • Finding C++ static initialization order problems

    - by Fred Larson
    We've run into some problems with the static initialization order fiasco, and I'm looking for ways to comb through a whole lot of code to find possible occurrences. Any suggestions on how to do this efficiently? Edit: I'm getting some good answers on how to SOLVE the static initialization order problem, but that's not really my question. I'd like to know how to FIND objects that are subject to this problem. Evan's answer seems to be the best so far in this regard; I don't think we can use valgrind, but we may have memory analysis tools that could perform a similar function. That would catch problems only where the initialization order is wrong for a given build, and the order can change with each build. Perhaps there's a static analysis tool that would catch this. Our platform is IBM XLC/C++ compiler running on AIX.

    Read the article

  • Returning in a static class constructor

    - by Martijn Courteaux
    Hello, This isn't valid code: public class MyClass { private static boolean yesNo = false; static { if (yesNo) { System.out.println("Yes"); return; // The return statement is the problem } System.exit(0); } } This is a stupid example, but in a static class constructor we can't return;. Why? Are there good reasons for this? Does someone know something more about this? So the reason why I should do return is to end constructing there. Thanks

    Read the article

  • Why is this static routing not working ?

    - by geeko
    Greeting gurus, I'm trying to develop a DHCP enforcement extension like Microsoft NAP. My trick to block dynamic-IP requesting machines (that don't meet certain policy) is to strip the default gateway (no default gateway) stated in the IP lease and set the lease subnet mask to 255.255.255.255. Now I need the blocked machines to be able to reach some specific locations (IPs) on the network. To allow for this, I'm including some static routes in the lease. For example, I'm including 10.10.10.11 via router 10.10.10.254 (the one to which the blocked machine that needs to access 10.10.10.11 is connected). Unfortunately, as soon as I set the default gateway to nothing, blocked machines cannot reach any of the added static routes. I also tried classless static routes. Any ideas ? any one knows how MS NAP actually do it ? Geeko

    Read the article

  • Exposing headers on iPhone static library

    - by leolobato
    Hello guys, I've followed this tutorial for setting up a static library with common classes from 3 projects we are working on. It's pretty simple, create a new static library project on xcode, add the code there, a change some headers role from project to public. The tutorial says I should add my library folder to the header search paths recursively. Is this the right way to go? I mean, on my library project, I have files separated in folders like Global/, InfoScreen/, Additions/. I was trying to setup one LOKit.h file on the root folder, and inside that file #import everything I need to expose. So on my host project I don't need to add the folder recursively to the header search path, and would just #import "LOKit.h". But I couldn't get this to work, the host project won't build complaining about all the classes I didn't add to LOKit.h, even though the library project builds. So, my question is, what is the right way of exposing header files when I setup a Cocoa Touch Static Library project on xCode?

    Read the article

  • Static struct in C++

    - by pingvinus
    Hi, I want to define an structure, where some math constants would be stored. Here what I've got now: struct consts { //salt density kg/m3 static const double gamma; }; const double consts::gamma = 2350; It works fine, but there would be more than 10 floating point constants, so I doesn't want to wrote 'static const' before each of them. And define something like that: static const struct consts { //salt density kg/m3 double gamma; }; const double consts::gamma = 2350; It look fine, but I got these errors: 1. member function redeclaration not allowed 2. a nonstatic data member may not be defined outside its class I wondering if there any C++ way to do it?

    Read the article

  • c++ defining a static member of a template class with type inner class pointer

    - by Jack
    I have a template class like here (in a header) with a inner class and a static member of type pointer to inner class template <class t> class outer { class inner { int a; }; static inner *m; }; template <class t> outer <t>::inner *outer <t>::m; when i want to define that static member i says "error: expected constructor, destructor, or type conversion before '*' token" on the last line (mingw32-g++ 3.4.5)

    Read the article

  • C++ Class Static variable problem - C programmer new to C++

    - by Microkernel
    Hi guys, I am a C programmer, but had learnt C++ @school longtime back. Now I am trying to write code in C++ but getting compiler error. Please check and tell me whats wrong with my code. typedef class _filter_session { private: static int session_count; /* Number of sessions count -- Static */ public: _filter_session(); /* Constructor */ ~_filter_session(); /* Destructor */ }FILTER_SESSION; _filter_session::_filter_session(void) { (this->session_count)++; return; } _filter_session::~_filter_session(void) { (this->session_count)--; return; } The error that I am getting is "error LNK2001: unresolved external symbol "private: static int _filter_session::session_count" (?session_count@_filter_session@@0HA)" I am using Visual Studio 2005 by the way. Plz plz help me. Regards, Microkernel

    Read the article

  • static setter method injection in Spring

    - by vishnu
    Hi, I have following requirement I wanted to pass http:\\localhost:9080\testws.cls value as setter injection through spring configuration file. How can i do this static variable setter injection for WSDL_LOCATION public class Code1 extends javax.xml.ws.Service { private final static URL CODE1_WSDL_LOCATION; static { URL url = null; try { url = new URL("http:\\localhost:9080\testws.cls"); } catch (MalformedURLException e) { e.printStackTrace(); } CODE1_WSDL_LOCATION = url; } public Code1(URL wsdlLocation, QName serviceName) { super(wsdlLocation, serviceName); } public Code1() { super(CODE1_WSDL_LOCATION, new QName("http://tempuri.org", "Code1")); } /** * * @return * returns Code1Soap */ @WebEndpoint(name = "Code1Soap") public Code1Soap getCode1Soap() { return (Code1Soap)super.getPort(new QName("http://tempuri.org", "Code1Soap"), Code1Soap.class); } } Please help me out.

    Read the article

  • Difference between static const char* and const char*.

    - by Will MacDonagh
    Could someone please explain the difference in how the 2 snippets of code are handled below? They definitely compile to different assembly code, but I'm trying to understand how the code might act differently. I understand that string literals are thrown into read only memory and are effectively static, but how does that differ from the explicit static below? struct Obj1 { void Foo() { const char* str( "hello" ); } }; and struct Obj2 { void Bar() { static const char* str( "hello" ); } };

    Read the article

< Previous Page | 8 9 10 11 12 13 14 15 16 17 18 19  | Next Page >