Search Results

Search found 15849 results on 634 pages for 'static linking'.

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

  • Best practise for overriding static classes

    - by maxp
    As it is not possible to override a static class in c#, if i want to override a method I generally define a delegate matching the signature of the static method, then modify the method along the lines of: public static void foo(int bar) { if (delegatename!=null) { delegatename.Invoke(bar); } else { //execute previous code as normal } } I feel a twinge of guilt, knowing this is a bit messy. Can anyone suggest a neater solution to this problem (other than rewriting the original structure)

    Read the article

  • Uses for static generic classes?

    - by Hightechrider
    What are the key uses of a Static Generic Class in C#? When should they be used? What examples best illustrate their usage? e.g. public static class Example<T> { public static ... } Since you can't define extension methods in them they appear to be somewhat limited in their utility. Web references on the topic are scarce so clearly there aren't a lot of people using them. Here's a couple:- http://ayende.com/Blog/archive/2005/10/05/StaticGenericClass.aspx http://stackoverflow.com/questions/686630/static-generic-class-as-dictionary

    Read the article

  • C# two classes with static members referring to each other

    - by Jerry
    Hi, I wonder why this code doesn't end up in endless recursion. I guess it's connected to the automatic initialization of static members to default values, but can someone tell me "step by step" how does 'a' get the value of 2 and 'b' of 1? public class A { public static int a = B.b + 1; } public class B { public static int b = A.a + 1; } static void Main(string[] args) { Console.WriteLine("A.a={0}, B.b={1}", A.a, B.b); //A.a=2, B.b=1 Console.Read(); }

    Read the article

  • Variable declarations in header files - static or not?

    - by Rob
    When refactoring away some #defines I came across declarations similar to the following in a C++ header file: static const unsigned int VAL = 42; const unsigned int ANOTHER_VAL = 37; The question is, what difference, if any, will the static make? Note that multiple inclusion of the headers isn't possible due to the classic #ifndef HEADER #define HEADER #endif trick (if that matters). Does the static mean only one copy of VAL is created, in case the header is included by more than one source file?

    Read the article

  • What effect does static const have on a namespace member

    - by user144182
    namespace MyNamespace { static const double GasConstant = 1.987; Class MyClass { // constructors, methods, etc. }; }; I previously had GasConstant declared within the MyClass declaration (and had a separate definition in the source file since C++ does not support const initialization of non-integral types). I however need to access it from other files and also logically it seems like it should reside at the namespace level. My questions is, what effect does static const have in this case? Clearly const means I can't assign a new value to GasConstant, but what does a static member at the namespace mean. Is this similar to filescope static effect, where the member is not accessible outside of the unit?

    Read the article

  • Static Property losing its value intermittently ?

    - by joedotnot
    Is there something fundamentally wrong with the following design, or can anyone see why would the static properties sometimes loose their values ? I have a class library project containing a class AppConfig; this class is consumed by a Webforms project. The skeleton of AppConfig class is as follows: Public Class AppConfig Implements IConfigurationSectionHandler Private Const C_KEY1 As String = "WebConfig.Key.1" Private Const C_KEY2 As String = "WebConfig.Key.2" Private Const C_KEY1_DEFAULT_VALUE as string = "Key1defaultVal" Private Const C_KEY2_DEFAULT_VALUE as string = "Key2defaultVal" Private Shared m_field1 As String Private Shared m_field2 As String Public Shared ReadOnly Property ConfigValue1() As String Get ConfigValue1= m_field1 End Get End Property Public Shared ReadOnly Property ConfigValue2() As String Get ConfigValue2 = m_field2 End Get End Property Public Shared Sub OnApplicationStart() m_field1 = ReadSetting(C_KEY1, C_KEY1_DEFAULT_VALUE) m_field2 = ReadSetting(C_KEY2, C_KEY1_DEFAULT_VALUE) End Sub Public Overloads Shared Function ReadSetting(ByVal key As String, ByVal defaultValue As String) As String Try Dim setting As String = System.Configuration.ConfigurationManager.AppSettings(key) If setting Is Nothing Then ReadSetting = defaultValue Else ReadSetting = setting End If Catch ReadSetting = defaultValue End Try End Function Public Function Create(ByVal parent As Object, ByVal configContext As Object, ByVal section As System.Xml.XmlNode) As Object Implements System.Configuration.IConfigurationSectionHandler.Create Dim objSettings As NameValueCollection Dim objHandler As NameValueSectionHandler objHandler = New NameValueSectionHandler objSettings = CType(objHandler.Create(parent, configContext, section), NameValueCollection) Return 1 End Function End Class The Static Properties get set once on application start, from the Application_Start event of the Global.asax Sub Application_Start(ByVal sender As Object, ByVal e As EventArgs) //Fires when the application is started AppConfig.OnApplicationStart() End Sub Thereafter, whenever we want to access a value in the Web.Config from anywhere, e.g. aspx page code-behind or another class or referenced class, we simply call the static property. For example, AppConfig.ConfigValue1() AppConfig.ConfigValue2() This is turn returns the value stored in the static backing fields m_field1, m_field2 Problem is sometimes these values are empty string, when clearly the Web.Config entry has values. Is there something fundamentally wrong with the above design, or is it reasonable to expect the static properties would keep their value for the life of the Application session?

    Read the article

  • Advantage of using a static member function instead of an equivalent non-static member function?

    - by jonathanasdf
    I was wondering whether there's any advantages to using a static member function when there is a non-static equivalent. Will it result in faster execution (because of not having to care about all of the member variables), or maybe less use of memory (because of not being included in all instances)? Basically, the function I'm looking at is an utility function to rotate an integer array representing pixel colours an arbitrary number of degrees around an arbitrary centre point. It is placed in my abstract Bullet base class, since only the bullets will be using it and I didn't want the overhead of calling it in some utility class. It's a bit too long and used in every single derived bullet class, making it probably not a good idea to inline. How would you suggest I define this function? As a static member function of Bullet, of a non-static member function of Bullet, or maybe not as a member of Bullet but defined outside of the class in Bullet.h? What are the advantages and disadvantages of each?

    Read the article

  • Odd C++ template behaviour with static member vars

    - by jon hanson
    This piece of code is supposed to calculate an approximation to e (i.e. the mathematical constant ~ 2.71828183) at compile-time, using the following approach; e1 = 2 / 1 e2 = (2 * 2 + 1) / (2 * 1) = 5 / 2 = 2.5 e3 = (3 * 5 + 1) / (3 * 2) = 16 / 6 ~ 2.67 e4 = (4 * 16 + 1) / (4 * 6) = 65 / 24 ~ 2.708 ... e(i) = (e(i-1).numer * i + 1) / (e(i-1).denom * i) The computation is returned via the result static member however, after 2 iterations it yields zero instead of the expected value. I've added a static member function f() to compute the same value and that doesn't exhibit the same problem. #include <iostream> #include <iomanip> // Recursive case. template<int ITERS, int NUMERATOR = 2, int DENOMINATOR = 1, int I = 2> struct CalcE { static const double result; static double f () {return CalcE<ITERS, NUMERATOR * I + 1, DENOMINATOR * I, I + 1>::f ();} }; template<int ITERS, int NUMERATOR, int DENOMINATOR, int I> const double CalcE<ITERS, NUMERATOR, DENOMINATOR, I>::result = CalcE<ITERS, NUMERATOR * I + 1, DENOMINATOR * I, I + 1>::result; // Base case. template<int ITERS, int NUMERATOR, int DENOMINATOR> struct CalcE<ITERS, NUMERATOR, DENOMINATOR, ITERS> { static const double result; static double f () {return result;} }; template<int ITERS, int NUMERATOR, int DENOMINATOR> const double CalcE<ITERS, NUMERATOR, DENOMINATOR, ITERS>::result = static_cast<double>(NUMERATOR) / DENOMINATOR; // Test it. int main (int argc, char* argv[]) { std::cout << std::setprecision (8); std::cout << "e2 ~ " << CalcE<2>::result << std::endl; std::cout << "e3 ~ " << CalcE<3>::result << std::endl; std::cout << "e4 ~ " << CalcE<4>::result << std::endl; std::cout << "e5 ~ " << CalcE<5>::result << std::endl; std::cout << std::endl; std::cout << "e2 ~ " << CalcE<2>::f () << std::endl; std::cout << "e3 ~ " << CalcE<3>::f () << std::endl; std::cout << "e4 ~ " << CalcE<4>::f () << std::endl; std::cout << "e5 ~ " << CalcE<5>::f () << std::endl; return 0; } I've tested this with VS 2008 and VS 2010, and get the same results in each case: e2 ~ 2 e3 ~ 2.5 e4 ~ 0 e5 ~ 0 e2 ~ 2 e3 ~ 2.5 e4 ~ 2.6666667 e5 ~ 2.7083333 Why does result not yield the expected values whereas f() does? According to Rotsor's comment below, this does work with GCC, so I guess the question is, am i relying on some type of undefined behaviour with regards to static initialisation order, or is this a bug with Visual Studio?

    Read the article

  • what is the exact difference between PHP static class and singleton class

    - by Saif Bechan
    I have always used a Singleton class for a registry object in PHP. As all Singleton classes I think the main method looks like this: class registry { public static function singleton() { if( !isset( self::$instance ) ) { self::$instance = new registry(); } return self::$instance; } public function doSomething() { echo 'something'; } } So whenever I need something of the registry class I use a function like this: registry::singleton()->doSomethine(); Now I do not understand what the difference is between creating just a normal static function. Will it create a new object if I just use a normal static class. class registry { public static function doSomething() { echo 'something'; } } Now I can just use: registry::doSomethine(); Can someone explain to me what the function is of the singleton class. I really do not understand this.

    Read the article

  • Serving CSS from a static domain

    - by Saif Bechan
    I want to serve my css and images from a static cookieless domain. Now my problem is how to point to the images from within my css files. I don't want to program my domain hard within the css file, for example: http://static.com/image.png I would rather have a variable pointing to the the image, so it works for every static domain i use. What is the best way for achieving this. Should i run the whole css file trough php and add the static domain in front of all the png references. A downside in this is that i have to place the whole css in html. Or is there another more optimized way of doing this.

    Read the article

  • how to deal with a static analyzer output

    - by Jim
    We have started using a static analyzer (Coverity) on our code base. We were promptly stupefied by the sheer amount of warnings we received (its in the hundreds of thousands) , it will take the entire team a few mounts to clear them all (obliviously impossible). the options we discussed so far are 1) hire a contractor to sort out the warning and fix them - he drawback: we will probably need very experiences people to do all these modifications, and no contractor will have required understanding of the code. 2) filter out the warning and deal only with the dangerous ones - the problem here is that our static analysis output will always be cluttered by warning making it difficult for us to isolate problems. also the filtering of the warning is also a major effort. either way, bringing our code to a state when the static analyzer can be a useful tool for us seems a monumental task. so how is it possible to work with the static analyzer without braining current development efforts into a complete stand still?

    Read the article

  • What's static function for in c?

    - by user198729
    I only see static methods by which we don't need to instantiate a class to call the method. What's the purpose of a static function? static GtkWidget * create_bbox (gint horizontal, char *title, gint spacing, gint layout) { ... }

    Read the article

  • Java: when to use static methods

    - by KP65
    Hello, I am wondering when to use static methods? Say If i have a class with a few getters and setters, a method or two, and i want those methods only to be invokable on an instance object of the class. Does this mean i should use a static method? e.g Obj x = new Obj(); x.someMethod or Obj.someMethod (is this the static way?) I'm rather confused!

    Read the article

  • Static variables in C and C++

    - by Naveen
    Is there any difference between a variable declared as static outside any function between C and C++. I read that static means file scope and the variables will not be accessible outside the file. I also read that in C, global variables are static . So does that mean that global variables in C can not be accessed in another file?

    Read the article

  • Why can't you call a non-static method from a static method?

    - by VoodooChild
    I have a static method [Method1] in my class, which calls another method [Method2] in the same class and is not a static method. But this is a no-no. I get this error: An object reference is required for the non-static field, method, or property "ClassName.MethodName()" Can someone please briefly describe why? including other things that might be related to this.

    Read the article

  • static, define, and const in C

    - by yCalleecharan
    Hi, I've read that static variables are used inside function when one doesn't want the variable value to change/initialize each time the function is called. But what about defining a variable static in the main program before "main" e.g. #include <stdio.h> static double m = 30000; int main(void) { value = m * 2 + 3; } Here the variable m has a constant value that won't get modified later in the main program. In the same line of thought what difference does it make to have these instead of using the static definition: const double m = 30000; or #define m 30000 //m or M and then making sure here to use double operations in the main code so as to convert m to the right data type. Thanks a lot...

    Read the article

  • Javascript - cannot make static reference to non-static function ....

    - by Ankur
    I am making a reference to the Javascript function splice() on an array and I get the error: "Cannot make a static reference to the non-static function splice()" What's going on - how is this a static reference, aren't I referencing an instance of an Array class and its method - how is that static? $(document).ready( function() { var queryPreds = new Array(); var queryObjs = new Array(); function remFromQuery(predicate) { for(var i=0; i<arrayName.length;i++ ) { if(queryPreds[i]==predicate) queryPreds.splice(i,1); queryObjs.splice(i,1); } } }

    Read the article

  • vc++ - static member is showing error

    - by prabhakaran
    I am using vc++(2010). I am trying to create a class for server side socket. Here is the header file #include<winsock.h> #include<string> #include<iostream> using namespace std; class AcceptSocket { // static SOCKET s; protected: SOCKET acceptSocket; public: AcceptSocket(){}; void setSocket(SOCKET socket); static void EstablishConnection(int portNo,string&); static void closeConnection(); static void StartAccepting(); virtual void threadDeal(); static DWORD WINAPI MyThreadFunction(LPVOID lpParam); }; SOCKET AcceptSocket::s; and the corresponding source file #include<NetWorking.h> #include<string> void AcceptSocket::setSocket(SOCKET s) { acceptSocket=s; } void AcceptSocket::EstablishConnection(int portno,string &failure) { WSAData w; int error = WSAStartup(0x0202,&w); if(error) failure=failure+"\nWSAStartupFailure"; if(w.wVersion != 0x0202) { WSACleanup(); failure=failure+"\nVersion is different"; } SOCKADDR_IN addr; addr.sin_family=AF_INET; addr.sin_port=htons(portno); addr.sin_addr.s_addr=htonl(INADDR_ANY); AcceptSocket::s=socket(AF_INET,SOCK_STREAM,IPPROTO_TCP); if(AcceptSocket::s == INVALID_SOCKET) failure=failure+"\nsocket creating error"; if(bind(AcceptSocket::s,(LPSOCKADDR) &addr,sizeof(addr)) == SOCKET_ERROR) failure=failure+"\nbinding error"; listen(AcceptSocket::s,SOMAXCONN); } void AcceptSocket::closeConnection() { if(AcceptSocket::s) closesocket(AcceptSocket::s); WSACleanup(); } void AcceptSocket::StartAccepting() { sockaddr_in addrNew; int size=sizeof(addrNew); while(1) { SOCKET temp=accept(AcceptSocket::s,(sockaddr *)&addrNew,&size); AcceptSocket * tempAcceptSocket=new AcceptSocket(); tempAcceptSocket->setSocket(temp); DWORD threadId; HANDLE thread=CreateThread(NULL,0,MyThreadFunction,(LPVOID)tempAcceptSocket,0,&threadId); } } DWORD WINAPI AcceptSocket::MyThreadFunction(LPVOID lpParam) { AcceptSocket * acceptsocket=(AcceptSocket *) lpParam; acceptsocket->threadDeal(); return 1; } void AcceptSocket::threadDeal() { "You didn't define threadDeal in the derived class"; } Now the main.cpp is #include<Networking.h> int main() { } When I am compiling The error I got is Error 1 error LNK2005: "private: static unsigned int AcceptSocket::s" (?s@AcceptSocket@@0IA) already defined in NetWorking.obj C:\Documents and Settings\prabhakaran\Desktop\check\check\main.obj check Error 2 error LNK1169: one or more multiply defined symbols found C:\Documents and Settings\prabhakaran\Desktop\check\Debug\check.exe 1 1 check Now anybody please enlighten me about this issue

    Read the article

  • Would you make this method Static or not?

    - by Adam Drummond
    During a code review I presented a method quickly to the team that I had made static and one person agreed that there was no reason for it to not be static and a person disagreed saying that he would not make it static because it wasn't necessary and just to be on the safe side for future modifications and testing. So I did quite a bit of research and obviously it's a specialized case but I would like to know what you would do in this situation and why? (Its basically a helper method I call from a few different methods, a very low traffic page. More for my knowledge and learning on Static.) private IEnumerable<Category> GetCategoryByID(int id, Context context) { var categoryQuery = from selectAllProc in context.SelectAll_sp() where selectAllProc.CategoryID == id select selectAllProc; return categoryQuery; }

    Read the article

  • Unable to access static var from Document Class in AS3

    - by omidomid
    I have a Document class called "CityModule", and an asset with class "City". Below is the coe for each. For some reason, I am unable to access the static variables of the City class from CityModule: CityModule.as: package { public class CityModule extends MovieClip { public function CityModule() { var buildings:Array = City.getBuildings(); } } } } City.as: package { import flash.display.MovieClip; public class City extends MovieClip { private static var _buildings:Array = [ {className:'City.Generic1', type:'generic'}, {className:'City.Generic2', type:'generic'}, {className:'City.Generic3', type:'generic'} ]; public function City(){ //empty } public static function getBuildings():Array{ return _buildings; } } } Doing this gives me a "Call to a possibly undefined method getBuildings" error. If I instantiate an instance of City, I can see any public/ getters/ setters perfectly fine. But static isn't working...

    Read the article

  • CodeIgniter static class question

    - by Josh K
    If I would like to have several static methods in my models so I can say User::get_registered_users() and have it do something like public static function get_registered_users() { $sql = "SELECT * FROM `users` WHERE `is_registered` = 0"; $this->db->query($sql); // etc... } Is it possible to access the $this->db object or create a new one for a static method?

    Read the article

  • How to free static member variable in C++?

    - by user299831
    Can anybody explain how to free memory of a static member Variable? In my understanding it can only be freed if all the instances of the class are destroyed. I am a little bit helpless at this point... Some Code to explain it: class ball { private: static SDL_Surface *ball_image; }; //FIXME: how to free static Variable? SDL_Surface* ball::ball_image = SDL_LoadBMP("ball.bmp");

    Read the article

  • C++ static virtual members?

    - by cvb
    Is it possible in C++ to have a member function that is both static and virtual? Apperantly, there isn't a straight-forward way to do it (static virtual member(); is a complie error), but at least a way to acheive the same effect? I.E: struct Object { struct TypeInformation; static virtual const TypeInformation &GetTypeInformation() const; }; struct SomeObject : public Object { static virtual const TypeInformation &GetTypeInformation() const; }; It makes sence to use GetTypeInformation() both on an instance (object->GetTypeInformation()) and on a class (SomeObject::GetTypeInformation()), which can be useful for comparsions and vital for templates. The only ways I can think of involves writing two functions / a function and a constant, per class, or use macros. Any other solutions?

    Read the article

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