Search Results

Search found 327 results on 14 pages for 'instantiation'.

Page 1/14 | 1 2 3 4 5 6 7 8 9 10 11 12  | Next Page >

  • Specialization of template after instantiation?

    - by Onur Cobanoglu
    Hi, My full code is too long, but here is a snippet that will reflect the essence of my problem: class BPCFGParser { public: ... ... class Edge { ... ... }; class ActiveEquivClass { ... ... }; class PassiveEquivClass { ... ... }; struct EqActiveEquivClass { ... ... }; struct EqPassiveEquivClass { ... ... }; unordered_map<ActiveEquivClass, Edge *, hash<ActiveEquivClass>, EqActiveEquivClass> discovered_active_edges; unordered_map<PassiveEquivClass, Edge *, hash<PassiveEquivClass>, EqPassiveEquivClass> discovered_passive_edges; }; namespace std { template <> class hash<BPCFGParser::ActiveEquivClass> { public: size_t operator()(const BPCFGParser::ActiveEquivClass & aec) const { } }; template <> class hash<BPCFGParser::PassiveEquivClass> { public: size_t operator()(const BPCFGParser::PassiveEquivClass & pec) const { } }; } When I compile this code, I get the following errors: In file included from BPCFGParser.cpp:3, from experiments.cpp:2: BPCFGParser.h:408: error: specialization of ‘std::hash<BPCFGParser::ActiveEquivClass>’ after instantiation BPCFGParser.h:408: error: redefinition of ‘class std::hash<BPCFGParser::ActiveEquivClass>’ /usr/include/c++/4.3/tr1_impl/functional_hash.h:44: error: previous definition of ‘class std::hash<BPCFGParser::ActiveEquivClass>’ BPCFGParser.h:445: error: specialization of ‘std::hash<BPCFGParser::PassiveEquivClass>’ after instantiation BPCFGParser.h:445: error: redefinition of ‘class std::hash<BPCFGParser::PassiveEquivClass>’ /usr/include/c++/4.3/tr1_impl/functional_hash.h:44: error: previous definition of ‘class std::hash<BPCFGParser::PassiveEquivClass>’ Now I have to specialize std::hash for these classes (because standard std::hash definition does not include user defined types). When I move these template specializations before the definition of class BPCFGParser, I get a variety of errors for a variety of different things tried, and somewhere (http://www.parashift.com/c++-faq-lite/misc-technical-issues.html) I read that: Whenever you use a class as a template parameter, the declaration of that class must be complete and not simply forward declared. So I'm stuck. I cannot specialize the templates after BPCFGParser definition, I cannot specialize them before BPCFGParser definition, how may I get this working? Thanks in advance, Onur

    Read the article

  • Understanding the "Instantiation" of Actionscript/Flash Objects

    - by parallax7d
    Could someone expand and clarify the different logical instantiations of objects in actionscript? So far it seems there are 3 layers of instantiations, for lack of a better term. The first one is declaring a variable/type. Next is instantiating that variable with something solid in the code, like a method or function? Is this just a way to glue things together? Then after that you instantiate it on the stage, is this something you have to do explicitly, or is it a side effect? Is this "3 layer" concept the correct way of looking at it, kind of like the MVC for flash app logic?

    Read the article

  • C# reflection instantiation

    - by NickLarsen
    I am currently trying to create a generic instance factory for which takes an interface as the generic parameter (enforced in the constructor) and then lets you get instantiated objects which implement that interface from all types in all loaded assemblies. The current implementation is as follows:     public class InstantiationFactory     {         protected Type Type { get; set; }         public InstantiationFactory()         {             this.Type = typeof(T);             if (!this.Type.IsInterface)             {                 // is there a more descriptive exception to throw?                 throw new ArgumentException(/* Crafty message */);             }         }         public IEnumerable GetLoadedTypes()         {             // this line of code found in other stack overflow questions             var types = AppDomain.CurrentDomain.GetAssemblies()                 .SelectMany(a = a.GetTypes())                 .Where(/* lambda to identify instantiable types which implement this interface */);             return types;         }         public IEnumerable GetImplementations(IEnumerable types)         {             var implementations = types.Where(/* lambda to identify instantiable types which implement this interface */                 .Select(x = CreateInstance(x));             return implementations;         }         public IEnumerable GetLoadedImplementations()         {             var loadedTypes = GetLoadedTypes();             var implementations = GetImplementations(loadedTypes);             return implementations;         }         private T CreateInstance(Type type)         {             T instance = default(T);             var constructor = type.GetConstructor(Type.EmptyTypes);             if (/* valid to instantiate test */)             {                 object constructed = constructor.Invoke(null);                 instance = (T)constructed;             }             return instance;         }     } It seems useful to me to have my CreateInstance(Type) function implemented as an extension method so I can reuse it later and simplify the code of my factory, but I can't figure out how to return a strongly typed value from that extension method. I realize I could just return an object:     public static class TypeExtensions     {         public object CreateInstance(this Type type)         {             var constructor = type.GetConstructor(Type.EmptyTypes);             return /* valid to instantiate test */ ? constructor.Invoke(null) : null;         }     } Is it possible to have an extension method create a signature per instance of the type it extends? My perfect code would be this, which avoids having to cast the result of the call to CreateInstance():     Type type = typeof(MyParameterlessConstructorImplementingType);     MyParameterlessConstructorImplementingType usable = type.CreateInstance();

    Read the article

  • gcc problem with explicit template instantiation?

    - by steve jaffe
    It is my understanding that either a declaration or typedef of a specialization ought to cause a template class to be instantiated, but this does not appear to be happening with gcc. E.g. I have a template class, template class Foo {}; I write class Foo<double>; or typedef Foo<double> DoubleFoo; but after compilation the symbol table of the resulting object file does not contain the members of Foo. If I create an instance: Foo<double> aFoo; then of course the symbols are all generated. Has anyone else experienced this and/or have an explanation?

    Read the article

  • Delayed instantiation with c# using statment

    - by fearofawhackplanet
    Is there any way to write a using statement without instantiating the IDisposable immediately? For example, if I needed to do something like: using (MyThing thing) { if (_config == null) { thing = new MyThing(); } else { thing = new MyThing(_config); } // do some stuff } // end of 'using' Is there an accepted pattern for cases like this? Or am I back to handling the IDisposable explicitly again?

    Read the article

  • Instantiation vs. Typed reference

    - by Farstucker
    Just when I think Im starting to understand the basics, I find something that brings me right back to reality. In this case, typed reference. I found an example similar to this: class Worker { Boss boss; public void Advise(Boss pBoss) { this.boss = pBoss; } How can you reference methods within the Boss class if its not static and not instantiated? I guess my real question is whats the difference between: Boss boss; and Boss boss = new Boss(); Thank you, FS

    Read the article

  • Python: Give a class its own `self` at instantiation time

    - by SuperDisk
    I've got a button class that you can instantiate like so: engine.createElement((0, 0), Button(code=print, args=("Stuff!",))) And when it is clicked it will print "Stuff!". However, I need the button to destroy itself whenever it is clicked. Something like this: engine.createElement((0, 0), Button(code=engine.killElement, args=(self,))) However, that would just kill the caller, because self refers to the caller at that moment. What I need to do is give the class its own 'self' in advance... I thought of just making the string 'self' refer to the self variable upon click, but what if I wanted to use the string 'self' in the arguments? What is the way to do this? Is my architecture all wrong or something? Thanks.

    Read the article

  • Java - Resize images upon class instantiation

    - by Tyler J Fisher
    Hey StackExchange GameDev community, I'm attempting to: Resize series of sprites upon instantiation of the class they're located in (x2) I've attempted to use the following code to resize the images, however my attempts have been unsuccessful. I have been unable to write an implementation that is even compilable, so no error codes yet. wLeft.getScaledInstance(wLeft.getWidth()*2, wLeft.getHeight()*2, Image.SCALE_FAST); I've heard that Graphics2D is the best option. Any suggestions? I think I'm probably best off loading the images into a Java project, resizing the images then outputting them to a new directory so as not to have to resize each sprite upon class instantiation. What do you think? Photoshopping each individual sprite is out of the question, unless I used a macro. Code: package game; //Import import java.awt.Image; import javax.swing.ImageIcon; public class Mario extends Human { Image wLeft = new ImageIcon("sprites\\mario\\wLeft.PNG").getImage(); //Constructor public Mario(){ super("Mario", 50); wLeft.getScaledInstance(wLeft.getWidth()*2, wLeft.getHeight()*2, Image.SCALE_FAST); } Thanks! Note: not homework, just thought Mario would be a good, overused starting point in game dev.

    Read the article

  • applyAngularVelocity causes error when called right after object instantiation

    - by Appeltaart
    I'm trying to make a physicsBody rotate as soon as it is instantiated. CCNode* ball = [CCBReader load:@"Ball"]; [ball.physicsBody applyForce:force]; [ball.physicsBody applyAngularImpulse:arc4random_uniform(360) - 180]; Applying force works fine, the last line however throws an error in cpBody.c line 123: cpAssertHard(body->w == body->w && cpfabs(body->w) != INFINITY, "Body's angular velocity is invalid."); When I don't apply force and merely rotate the problem persists. If I send applyAngularImpulse at some later point (in this case on a touch) it does work. Is this function not supposed to be called right after instantiation, or is this a bug?

    Read the article

  • Multiple Object Instantiation

    - by Ricky Baby
    I am trying to get my head around object oriented programming as it pertains to web development (more specifically PHP). I understand inheritance and abstraction etc, and know all the "buzz-words" like encapsulation and single purpose and why I should be doing all this. But my knowledge is falling short with actually creating objects that relate to the data I have in my database, creating a single object that a representative of a single entity makes sense, but what are the best practises when creating 100, 1,000 or 10,000 objects of the same type. for instance, when trying to display a list of the items, ideally I would like to be consistent with the objects I use, but where exactly should I run the query/get the data to populate the object(s) as running 10,000 queries seems wasteful. As an example, say I have a database of cats, and I want a list of all black cats, do I need to set up a FactoryObject which grabs the data needed for each cat from my database, then passes that data into each individual CatObject and returns the results in a array/object - or should I pass each CatObject it's identifier and let it populate itself in a separate query.

    Read the article

  • Obtain reference to Parent object during instantiation

    - by GoldBishop
    I have a situation where a custom class is a property of another class. What i need to be able to do, if it is possible at all, is obtain a reverse to the "parent" class (ie the the class that holds the current class as a property). For Instance: Public Class Class1 ... public readonly property Prop11 as Class2 public property Prop12 as String ... End Class Public Class Class2 ... private _par as Class1 private _var21 as string ... Public Sub New(...) me._par = ???? ... End Sub public readonly property Prop21 as string Get return me._par.Prop12 & me._var21 End Get End Property ... End Class Ultimately, i am trying to access other properties within Class1 from Class2 as they do have substance for information from within Class2. There are several other classes within Class1 that provide descriptive information to other classes contained within it as properties but the information is not extensible to all of the classes through Inheritance, as Class1 is being used as a resource bin for the property classes and the application itself. Diagram, lazy design ;): Application <- Class1.Prop12 Application <- Class1.Prop11.Prop21 Question: Is it possible to get a recursion through this design setup?

    Read the article

  • Controller instantiation in Yii framework by directory and namespace

    - by Einoras Bružas
    Yii framework supports modules and also subdirectories in controllers directory, so path to some specific action could be /index.php?r=module/controller/action or /index.php?r=subdirectoryInControllerDir/controller/action. My goal here is to have multiple subdirectories in controllers dir. Inside these folders I would create Controllers with the same names as parent ones using namespaces. However if I wrote namespace mynamespace; class MyController extends \MyController { } Yii would load MyController instead of mynamespace\MyController; Any suggestions here?

    Read the article

  • Is it possible to restrict instantiation of an object to only one other (parent) object in VB.NET?

    - by Casey
    VB 2008 .NET 3.5 Suppose we have two classes, Order and OrderItem, that represent some type of online ordering system. OrderItem represents a single line item in an Order. One Order can contain multiple OrderItems, in the form of a List(of OrderItem). Public Class Order Public Property MyOrderItems() as List(of OrderItem) End Property End Class It makes sense that an OrderItem should not exist without an Order. In other words, an OrderItem class should not be able to be instantiated on its own, it should be dependent on an Order class to contain it and instantiate it. However, the OrderItem should be public in scope so that it's properties are accessible to other objects. So, the requirements for OrderItem are: Can not be instantiated as a stand alone object; requires Order to exist. Must be public so that any other object can access it's properties/methods through the Order object. e.g. Order.OrderItem(0).ProductID. OrderItem should be able to be passed to other subs/functions that will operate on it. How can I achieve these goals? Is there a better approach?

    Read the article

  • inspect C++ template instantiation

    - by aaa
    hello. Is there some utility which would allow me to inspect template instantiation? my compiler is g++ or Intel. Specific points I would like: Step by step instantiation. Instantiation backtrace (can hack this by crashing compiler. Better method?) Inspection of template parameters. Thanks

    Read the article

  • Why is there a "new" keyword in Go?

    - by dystroy
    I'm still puzzled as why we have new in Go. &Thing{} is as clear and concise as new(Thing) to Go coders and it uses only constructs you often use elsewhere. It's also more extensible as you might change it to &Thing{3} or &Thing{Feets:7}. In my opinion, having a supplementary keyword is costly, it makes the language more complex and adds to what you must know. And it might mask to newcomers what's behind instantiating a struct. It also makes one more reserved word. So what's the reasoning behind new ? Is it something useful ? Should we use it ?

    Read the article

  • Why is there a "new" in Go?

    - by dystroy
    I'm still puzzled as why we have new in Go. When you want to instantiate a struct, you do t := Thing{} and, obviously, you can get a pointer to a new instance by doing t := &Thing{} But there's also this possibility : t := new(Thing) This last one seems a little alien to me. &Thing{} is as clear and concise as new(Thing) and it uses only constructs you often use elsewhere. It's also more extensible as you might change it to &Thing{3} or &Thing{Feets:7}. In my opinion, having a supplementary keyword is costly, it makes the language more complex and adds to what you must know. And it might mask to newcomers what's behind instantiating a struct. It also makes one more reserved word. So what's the reasoning behind new ? Is it something useful ? Should we use it ?

    Read the article

  • const return value and template instantiation

    - by Rimo
    From Herb Sutter's GotW #6 Return-by-value should normally be const for non-builtin return types. .... Note: Lakos (pg. 618) argues against returning const value, and notes that it is redundant for builtins anyway (for example, returning "const int"), which he notes may interfere with template instantiation. .... While Sutter seems to disagree on whether to return a const value or non-const value when returning an object of a non-built type by value with Lakos, he generally agrees that returning a const value of a built-in type (e.g const int) is not a good idea. While I understand why that is useless because the return value cannot be modified as it is an rvalue, I cannot find an example of how that might interfere with template instantiation. Please give me an example of how having a const qualifier for a return type might interfere with template instantiation.

    Read the article

  • C++ ambiguous template instantiation

    - by aaa
    the following gives me ambiguous template instantiation with nvcc (combination of EDG front-end and g++). Is it really ambiguous, or is compiler wrong? I also post workaround à la boost::enable_if template<typename T> struct disable_if_serial { typedef void type; }; template<> struct disable_if_serial<serial_tag> { }; template<int M, int N, typename T> __device__ //static typename disable_if_serial<T>::type void add_evaluate_polynomial1(double *R, const double (&C)[M][N], double x, const T &thread) { // ... } template<size_t M, size_t N> __device__ static void add_evaluate_polynomial1(double *R, const double (&C)[M][N], double x, const serial_tag&) { for (size_t i = 0; i < M; ++i) add_evaluate_polynomial1(R, C, x, i); } // ambiguous template instantiation here. add_evaluate_polynomial1(R, C, x, serial_tag());

    Read the article

  • Catch a PHP Object Instantiation Error

    - by Rob Wilkerson
    It's really irking me that PHP considers the failure to instantiate an object a Fatal Error (which can't be caught) for the application as a whole. I have set of classes that aren't strictly necessary for my application to function--they're really a convenience. I have a factory object that attempts to instantiate the class variant that's indicated in a config file. This mechanism is being deployed for message storage and will support multiple store types: DatabaseMessageStore FileMessageStore MemcachedMessageStore etc. A MessageStoreFactory class will read the application's preference from a config file, instantiate and return an instance of the appropriate class. It might be easy enough to slap a conditional around the instantiation to ensure that class_exists(), but MemcachedMessageStore extends PHP's Memcached class. As a result, the class_exists() test will succeed--though instantiation will fail--if the memcached bindings for PHP aren't installed. Is there any other way to test whether a class can be instantiated properly? If it can't, all I need to do is tell the user which features won't be available to them, but let them continue one with the application. Thanks.

    Read the article

  • RapidXML - does not compile ?

    - by milan
    Hi, I am novice to rapidXML but first impresion was not positive, I made simple Visual Studio 6 C++ Hello World Application and added RapidXML hpp files to project and in main.cpp I put: #include "stdafx.h" #include < iostream > #include < string > #include "rapidxml.hpp" using namespace std; using namespace rapidxml; int main ( ) { char x[] = "<Something>Text</Something>\0" ; //<<<< funktioniert, aber mit '*' nicht xml_document<> doc ; doc.parse<0>(x) ; cout << "Name of my first node is: " << doc.first_node()->name() << endl ; xml_node<>* node = doc.first_node("Something") ; cout << "Node 'Something' has value: " << node->value() << endl ; } And it does not compile, any help ? Is RapidXML possible to run with Visual Studio 6 ? Error I am getting are: --------------------Configuration: aaa - Win32 Debug-------------------- Compiling... rapidxml.cpp c:\Parser\rapidxml.cpp(310) : error C2039: 'size_t' : is not a member of 'std' c:\Parser\rapidxml.cpp(320) : error C2039: 'size_t' : is not a member of 'std' c:\Parser\rapidxml.cpp(320) : error C2039: 'size_t' : is not a member of 'std' c:\Parser\rapidxml.cpp(385) : error C2039: 'size_t' : is not a member of 'std' c:\Parser\rapidxml.cpp(639) : see reference to class template instantiation 'rapidxml::memory_pool<Ch>' being compiled c:\Parser\rapidxml.cpp(417) : error C2039: 'size_t' : is not a member of 'std' c:\Parser\rapidxml.cpp(639) : see reference to class template instantiation 'rapidxml::memory_pool<Ch>' being compiled c:\Parser\rapidxml.cpp(417) : error C2039: 'size_t' : is not a member of 'std' c:\Parser\rapidxml.cpp(639) : see reference to class template instantiation 'rapidxml::memory_pool<Ch>' being compiled c:\Parser\rapidxml.cpp(448) : error C2039: 'size_t' : is not a member of 'std' c:\Parser\rapidxml.cpp(639) : see reference to class template instantiation 'rapidxml::memory_pool<Ch>' being compiled c:\Parser\rapidxml.cpp(448) : error C2039: 'size_t' : is not a member of 'std' c:\Parser\rapidxml.cpp(639) : see reference to class template instantiation 'rapidxml::memory_pool<Ch>' being compiled c:\Parser\rapidxml.cpp(476) : error C2039: 'size_t' : is not a member of 'std' c:\Parser\rapidxml.cpp(639) : see reference to class template instantiation 'rapidxml::memory_pool<Ch>' being compiled c:\Parser\rapidxml.cpp(579) : error C2039: 'size_t' : is not a member of 'std' c:\Parser\rapidxml.cpp(639) : see reference to class template instantiation 'rapidxml::memory_pool<Ch>' being compiled c:\Parser\rapidxml.cpp(599) : error C2039: 'size_t' : is not a member of 'std' c:\Parser\rapidxml.cpp(639) : see reference to class template instantiation 'rapidxml::memory_pool<Ch>' being compiled c:\Parser\rapidxml.cpp(681) : error C2039: 'size_t' : is not a member of 'std' c:\Parser\rapidxml.cpp(790) : see reference to class template instantiation 'rapidxml::xml_base<Ch>' being compiled c:\Parser\rapidxml.cpp(700) : error C2039: 'size_t' : is not a member of 'std' c:\Parser\rapidxml.cpp(790) : see reference to class template instantiation 'rapidxml::xml_base<Ch>' being compiled c:\Parser\rapidxml.cpp(721) : error C2039: 'size_t' : is not a member of 'std' c:\Parser\rapidxml.cpp(790) : see reference to class template instantiation 'rapidxml::xml_base<Ch>' being compiled c:\Parser\rapidxml.cpp(751) : error C2039: 'size_t' : is not a member of 'std' c:\Parser\rapidxml.cpp(790) : see reference to class template instantiation 'rapidxml::xml_base<Ch>' being compiled c:\Parser\rapidxml.cpp(786) : error C2039: 'size_t' : is not a member of 'std' c:\Parser\rapidxml.cpp(790) : see reference to class template instantiation 'rapidxml::xml_base<Ch>' being compiled c:\Parser\rapidxml.cpp(787) : error C2039: 'size_t' : is not a member of 'std' c:\Parser\rapidxml.cpp(790) : see reference to class template instantiation 'rapidxml::xml_base<Ch>' being compiled c:\Parser\rapidxml.cpp(836) : error C2039: 'size_t' : is not a member of 'std' c:\Parser\rapidxml.cpp(876) : see reference to class template instantiation 'rapidxml::xml_attribute<Ch>' being compiled c:\Parser\rapidxml.cpp(856) : error C2039: 'size_t' : is not a member of 'std' c:\Parser\rapidxml.cpp(876) : see reference to class template instantiation 'rapidxml::xml_attribute<Ch>' being compiled c:\Parser\rapidxml.cpp(936) : error C2039: 'size_t' : is not a member of 'std' c:\Parser\rapidxml.cpp(1345) : see reference to class template instantiation 'rapidxml::xml_node<Ch>' being compiled c:\Parser\rapidxml.cpp(958) : error C2039: 'size_t' : is not a member of 'std' c:\Parser\rapidxml.cpp(1345) : see reference to class template instantiation 'rapidxml::xml_node<Ch>' being compiled c:\Parser\rapidxml.cpp(981) : error C2039: 'size_t' : is not a member of 'std' c:\Parser\rapidxml.cpp(1345) : see reference to class template instantiation 'rapidxml::xml_node<Ch>' being compiled c:\Parser\rapidxml.cpp(1004) : error C2039: 'size_t' : is not a member of 'std' c:\Parser\rapidxml.cpp(1345) : see reference to class template instantiation 'rapidxml::xml_node<Ch>' being compiled c:\Parser\rapidxml.cpp(1025) : error C2039: 'size_t' : is not a member of 'std' c:\Parser\rapidxml.cpp(1345) : see reference to class template instantiation 'rapidxml::xml_node<Ch>' being compiled c:\Parser\rapidxml.cpp(1045) : error C2039: 'size_t' : is not a member of 'std' c:\Parser\rapidxml.cpp(1345) : see reference to class template instantiation 'rapidxml::xml_node<Ch>' being compiled Error executing cl.exe. rapidxml.obj - 25 error(s), 0 warning(s)

    Read the article

  • Check if a type is an instantiation of a template

    - by Pedro Lacerda
    I have structs like struct RGBA (T) {/* ... */} struct BMPFile (DataT) if (is(DataT == RGBA)) {/* ... */} But is(DataT == RGBA) cannot work because DataT is a type and RGBA is a template. Instead I need check if a type is an instantiation of a template in order to declare file like BMPFile!(RGBA!ushort) file; In a comment @FeepingCreature showed struct RGBA(T) { alias void isRGBAStruct; } struct BMPFile (DataT) if (is(DataT.isRGBAStruct)) {} Although to be working I have no tips on alias void isRGBAStruct.

    Read the article

  • java singleton instantiation

    - by jurchiks
    I've found three ways of instantiating a Singleton, but I have doubts as to whether any of them is the best there is. I'm using them in a multi-threaded environment and prefer lazy instantiation. Sample 1: private static final ClassName INSTANCE = new ClassName(); public static ClassName getInstance() { return INSTANCE; } Sample 2: private static class SingletonHolder { public static final ClassName INSTANCE = new ClassName(); } public static ClassName getInstance() { return SingletonHolder.INSTANCE; } Sample 3: private static ClassName INSTANCE; public static synchronized ClassName getInstance() { if (INSTANCE == null) INSTANCE = new ClassName(); return INSTANCE; } The project I'm using ATM uses Sample 2 everywhere, but I kind of like Sample 3 more. There is also the Enum version, but I just don't get it. The question here is - in which cases I should/shouldn't use any of these variations? I'm not looking for lengthy explanations though (there's plenty of other topics about that, but they all eventually turn into arguing IMO), I'd like it to be understandable with few words.

    Read the article

  • Sending string from class to Form1

    - by Farstucker
    Although there are some similar questions I’m having difficulties finding an answer on how to receive data in my form from a class. I have been trying to read about instantiation and its actually one of the few things that does make sense to me :) but if I were to instantiate my form, would I not have two form objects? To simplify things, lets say I have a some data in Class1 and I would like to pass a string into a label on Form1. Is it legal to instantiate another form1? When trying to do so it looks like I can then access label1.Text but the label isn’t updating. The only thing I can think of is that the form needs to be redrawn or there is some threading issue that I’m unaware of. Any insight you could provide would be greatly appreciated.

    Read the article

  • Calling a method on an object a bunch of times versus constructing an object a bunch of times

    - by Ami
    I have a List called myData and I want to apply a particular method (someFunction) to every element in the List. Is calling a method through an object's constructor slower than calling the same method many times for one particular object instantiation? In other words, is this: for(int i = 0; i < myData.Count; i++) myClass someObject = new myClass(myData[i]); slower than this: myClass someObject = new myClass(); for(int i = 0; i < myData.Count; i++) someObject.someFunction(myData[i]); ? If so, how much slower?

    Read the article

  • Factories, or Dependency Injection for object instantiation in WCF, when coding against an interface

    - by Saajid Ismail
    Hi I am writing a client/server application, where the client is a Windows Forms app, and the server is a WCF service hosted in a Windows Service. Note that I control both sides of the application. I am trying to implement the practice of coding against an interface: i.e. I have a Shared assembly which is referenced by the client application. This project contains my WCF ServiceContracts and interfaces which will be exposed to clients. I am trying to only expose interfaces to the clients, so that they are only dependant on a contract, not any specific implementation. One of the reasons for doing this is so that I can have my service implementation, and domain change at any time without having to recompile and redeploy the clients. The interfaces/contracts will in this case not change. I only need to recompile and redeploy my WCF service. The design issue I am facing now, is: on the client, how do I create new instances of objects, e.g. ICustomer, if the client doesn't know about the Customer concrete implementation? I need to create a new customer to be saved to the DB. Do I use dependency injection, or a Factory class to instantiate new objects, or should I just allow the client to create new instances of concrete implementations? I am not doing TDD, and I will typically only have one implementation of ICustomer or any other exposed interface.

    Read the article

1 2 3 4 5 6 7 8 9 10 11 12  | Next Page >