Search Results

Search found 15087 results on 604 pages for 'copy constructor'.

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

  • Java: initialization problem with private-final-int-value and empty constructor

    - by HH
    $ javac InitInt.java InitInt.java:7: variable right might not have been initialized InitInt(){} ^ 1 error $ cat InitInt.java import java.util.*; import java.io.*; public class InitInt { private final int right; InitInt(){} public static void main(String[] args) { // I don't want to assign any value. // just initialize it, how? InitInt test = new InitInt(); System.out.println(test.getRight()); // later assiging a value } public int getRight(){return right;} } Initialization problem with Constructor InitInt{ // Still the error, "may not be initialized" // How to initialise it? if(snippetBuilder.length()>(charwisePos+25)){ right=charwisePos+25; }else{ right=snippetBuilder.length()-1; } }

    Read the article

  • Why is the base() constructor not necessary?

    - by Earlz
    Hello, I have a class structure like abstract class Animal { public Animal(){ //init stuff.. } } class Cat : Animal { public Cat(bool is_keyboard) : base() //NOTE here { //other init stuff } } Now then, look at the noted line. If you remove : base() then it will compile without an error. Why is this? Is there a way to disable this behavior? I have had multiple bugs now from forgetting the base() which I would have thought to be required on such a special thing as a constructor.

    Read the article

  • Spring: Inject static member (System.in) via constructor

    - by Julian Lettner
    I wrote some sort of console client for a simple application. To be more flexible, I thought it would be nice to only depend on java.io.Input-/OutputStream, instead of accessing System.in/out directly. I renamed the class ConsoleClient to StreamClient, added setters and made sure that the instance fields are used instead of System.in/out. At the moment my client code looks like this: ApplicationContext appCtx = new ClassPathXmlApplicationContext("..."); StreamClient cc = (StreamClient) appCtx.getBean("streamClient"); cc.setInputStream(System.in); cc.setOutputStream(System.out); cc.run(); // start client Question: Is there a way to move lines 3 and 4 into the Spring configuration (preferably constructor injection)? Thanks for your time.

    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

  • Better to use constructor or method factory pattern?

    - by devoured elysium
    I have a wrapper class for the Bitmap .NET class called BitmapZone. Assuming we have a WIDTH x HEIGHT bitmap picture, this wrapper class should serve the purpose of allowing me to send to other methods/classes itself instead of the original bitmap. I can then better control what the user is or not allowed to do with the picture (and I don't have to copy the bitmap lots of times to send for each method/class). My question is: knowing that all BitmapZone's are created from a Bitmap, what do you find preferrable? Constructor syntax: something like BitmapZone bitmapZone = new BitmapZone(originalBitmap, x, y, width, height); Factory Method Pattern: BitmapZone bitmapZone = BitmapZone.From(originalBitmap, x , y, width, height); Factory Method Pattern: BitmapZone bitmapZone = BitmapZone.FromBitmap(originalBitmap, x, y, width, height); Other? Why? Thanks

    Read the article

  • Relevance of 'public' constructor in abstract class.

    - by Amby
    Is there any relevance of a 'public' constructor in an abstract class? I can not think of any possible way to use it, in that case shouldn't it be treated as error by compiler (C#, not sure if other languages allow that). Sample Code: internal abstract class Vehicle { public Vehicle() { } } The C# compiler allows this code to compile, while there is no way i can call this contructor from the outside world. It can be called from derived classes only. So shouldn't it allow 'protected' and 'private' modifiers only. Please comment.

    Read the article

  • C++ Singleton Constructor and Destructor

    - by Aaron
    Does it matter if the constructor/destructor implementation is provided in the header file or the source file? For example, which way is preferred and why? Way 1: class Singleton { public: ~Singleton() { } private: Singleton() { } }; Way 2: class Singleton { public: ~Singleton(); private: Singleton(); }; In the source .cc file: Singleton::Singleton() { } Singleton::~Singleton() { } Initially, I have the implementation in a source file, but I was asked to remove it. Does anyone know why?

    Read the article

  • Handling Exceptions that happen in a asp.net MVC Controller Constructor

    - by Jason
    What's the best way to handle exceptions that happen from within a controller's constructor? All I can think of to do is use Application_OnError() or put a try/catch in my ControllerFactory. Neither of these solutions seem ideal. Application_OnError is to broad - I have some non-mvc content in the site that has its own error handling. Using a try/catch block seems kinda hacky. If I'm serving different content type -html/text/json/rss.... I would like to be able to handle the exception from within the action method instead of having to write all kinds of conditions to determine what kind of error message to serve. Am I missing something here, or has anyone else dealt with this?

    Read the article

  • Template class implicit copy constructor issues

    - by Nate
    Stepping through my program in gdb, line 108 returns right back to the calling function, and doesn't call the copy constructor in class A, like (I thought) it should: template <class S> class A{ //etc... A( const A & old ){ //do stuff... } //etc... }; template <class T> class B{ //etc... A<T> ReturnsAnA(){ A<T> result; // do some stuff with result return result; //line 108 } //etc... }; Any hints? I've banged my head against the wall about this for 4 hours now, and can't seem to come up with what's happening here.

    Read the article

  • C++ Constructor Initializer List - using member functions of initialized members

    - by Andy
    I've run into the following a few times with initializer lists and I've never been able to explain it well. Can anyone explain why exactly the following fails (I don't have a compiler to catch typos, so bear with me): class Foo { public: Foo( int i ) : m_i( i ) {} //works with no problem int getInt() {return m_i;} ~Foo {} private: int m_i; }; class Bar { public: Bar() : m_foo( 5 ), //this is ok m_myInt( m_foo.getInt() ) //runtime error, seg 11 {} ~Bar() {} private: Foo m_foo; int m_myInt; }; When trying to call member functions of members initialized higher up the initializer list, I get seg faults. I seem to recall this is a known problem (or perhaps somehow by design) but I've never seen it well described. The attached example is contrived with plain old data types, but substitute the Bar::m_myInt with another object lacking a default (empty) constructor and the issue is more real. Can anyone enlighten me? Thanks!

    Read the article

  • Error Instantiating an Inner Class in Parent's Constructor...

    - by stormin986
    In my application's main class (subclass of Application), I have a public inner class that simply contains 3 public string objects. In the parent class I declare an object of that inner class. public class MainApplication extends Application { public class Data { public String x; public String y; public String z; } private Data data; MainApplication() { data = new Data() data.x = "String"; } } After I instantiate the object in the constructor, I get a runtime error when I try to assign any of the inner class object's variables. Any idea what's up here??

    Read the article

  • Constructor with non-instance variable assistant?

    - by Robert Fischer
    I have a number of classes that look like this: class Foo(val:BasicData) extends Bar(val) { val helper = new Helper(val) val derived1 = helper.getDerived1Value() val derived2 = helper.getDerived2Value() } ...except that I don't want to hold onto an instance of "helper" beyond the end of the constructor. In Java, I'd do something like this: public class Foo { final Derived derived1, derived2; public Foo(BasicData val) { Helper helper = new Helper(val); derived1 = helper.getDerived1Value(); derived2 = helper.getDerived2Value(); } } So how do I do something like that in Scala? I'm aware of creating a helper object of the same name of the class with an apply method: I was hoping for something slightly more succinct.

    Read the article

  • C++ catch constructor exception

    - by aaa
    hi. I do not seem to understand how to catch constructor exception. Here is relevant code: struct Thread { rysq::cuda::Fock fock_; template<class iterator> Thread(const rysq::cuda::Centers &centers, const iterator (&blocks)[4]) : fock_() { if (!fock_) throw; } }; Thread *ct; try { ct = new Thread(centers_, blocks); } catch(...) { return false; } // catch never happens, So catch statement do not execute and I get unhandled exception. What did I do wrong? this is straight C++ using g++.

    Read the article

  • Disallow private constructor invocation in friend function

    - by user2907032
    Is there any way to not allow private construction in friend function, In case we do have private constructor with friend function in our class. Only Static method should be responsible for object creation and other than this compiler should flash error message #include <iostream> #include <memory> using namespace std; class a { public: void see () { cout<<"Motimaa"; } static a& getinstance() { static a instance; return instance; } private: a() {}; friend void access(); }; void access () { a obj; obj.see();//still friend function can access } int main() { a::getinstance().see(); access(); return 1; }

    Read the article

  • C# Closing a form during a constructor

    - by pm_2
    Is it possible to close a form while the constructor is executing (or simply to stop it showing at this stage)? I have the following code: public partial class MyForm : Form { public MyForm() { if (MyFunc()) { this.Close(); } } } Which errors in Main(), here: static void Main() { ... // Following line errors Application.Run(new MyForm()); } I’ve tried checking the result of MyForm like this: static void Main() { ... MyForm frm = new MyForm(); if (frm != null) { // Following line errors Application.Run(frm); } } But that doesn’t seem to help. Can anyone tell me a way around this, please? Maybe a way to check the form to see if it still exists?

    Read the article

  • How do I get the default constructor value in a function

    - by lax
    public class AppXmlLogWritter { public int randomNumber; public string LogDateTime = ""; public AppXmlLogWritter() { Random random = new Random(); randomNumber = random.Next(9999); LogDateTime = DateTime.Now.ToString("yyyyMMdd HHmmss"); } public AppXmlLogWritter(int intLogIDPrefix, string strLogApplication, string strLogFilePath) { LogIDPrefix = intLogIDPrefix; LogApplication = strLogApplication; LogFilePath = strLogFilePath; } public void WriteXmlLog(string LogFlag) { string value=LogDateTime + randomNumber;**//Here i m getting 0 no date time and random number generated** } } AppXmlLogWritter objParameterized = new AppXmlLogWritter(1234, "LogApplication", "LogFilepath"); AppXmlLogWritter objParmeterlessConstr = new AppXmlLogWritter(); objParameterized.WriteXmlLog("0", "LogFlag"); How do I get the default constructor value in this function?

    Read the article

  • C# Constructor Problem When Using Generics

    - by Jimbo
    Please see an example of my code below: public class ScrollableCheckboxList { public List<ScrollableCheckboxItem> listitems; public void ScrollableCheckboxList<TModel>(IEnumerable<TModel> items, string valueField, string textField, string titleField) where TModel : class { listitems = new List<ScrollableCheckboxItem>(); foreach (TModel item in items) { Type t = typeof(TModel); PropertyInfo[] props = new [] { t.GetProperty(textField), t.GetProperty(valueField), t.GetProperty(titleField) }; listitems.Add(new ScrollableCheckboxItem { text = props[0].GetValue(item, null).ToString(), value = props[1].GetValue(item, null).ToString(), title = props[2].GetValue(item, null).ToString() }); } } } The code produces the following error: 'ScrollableCheckboxList': member names cannot be the same as their enclosing type This clearly means that there is a method in the class that has the same name as the class, but usually insinuates that the method is trying to return something (which is not allowed) In my case, all I have done is declare a constructor - why would this be a problem?

    Read the article

  • Constructor Definition

    - by mctl87
    Ok so i have a class Vector: #include <cstdlib> class Vec { private: size_t size; int * ptab; public: Vec(size_t n); ~Vec() {delete [] ptab;} size_t size() const {return size;} int & operator[](int n) {return ptab[n];} int operator[](int n) const {return ptab[n];} void operator=(Vec const& v); }; inline Vec::Vec(size_t n) : size(n), ptab(new int[n]) { } and the problem is that in one of my homework exercises i have to extend constructor def, so all elements will be initialized with zeros. I thought i know the basics but cant get through this dynamic array -.- ps. sry for gramma and other mistakes ;)

    Read the article

  • Java Copy/Paste org.w3c.dom.Node between two running copies of the same program

    - by Jay
    I have a program that shows a tree representation of an XML file. Using a number of sources online I have Copy/Paste within a single instance of the program working. I am using the system Clipboard. What I need though is to be able to copy a node from one instance of the program and paste to a different instance of the same program. I have tried a number of different options, all resulting in the same behavior. When pasting from within the same application the clipboardContent contains a "transferable" object with the correct data along with an isLocal set to "true". When I perform the copy and then attempt the paste from another instance of the same program running the clipboardContent contains a "flavorsToData" HashMap and "flavors" values, the check for isDataFlavorSupported fails (never hits my custom class that represents the new flavor). I have tried using different values for the requestor object in the getContents() call. Likewise I have tried a few different ClipboardOwners for the setContent() call. Neither seem to change the behavior in any way. I am sorely tempted to convert the node that is being copied back into a textual XML format, and then on the paste convert back to the DOM model, but would rather not if possible. This class is used to define the DataFlavor and transferable object: import java.awt.datatransfer.*; import org.w3c.dom.Node; public class NodeCopyPaste implements Transferable { static public DataFlavor NodeFlavor; private DataFlavor [] supportedFlavors = {NodeFlavor}; public Node aNode; public NodeCopyPaste (Node paraNode) { aNode = paraNode; try { NodeFlavor = new DataFlavor (Class.forName ("org.w3c.dom.Node"), "Node"); } catch (ClassNotFoundException e) { e.printStackTrace (); } } public synchronized DataFlavor [] getTransferDataFlavors () { return (supportedFlavors); } public boolean isDataFlavorSupported (DataFlavor nodeFlavor) { return (nodeFlavor.equals (NodeFlavor)); } public synchronized Object getTransferData (DataFlavor nFlavor) throws UnsupportedFlavorException { if (nFlavor.equals (NodeFlavor)) return (this); else throw new UnsupportedFlavorException (nFlavor); } public void lostOwnership (Clipboard parClipboard, Transferable parTransferable) { } } I define a Clipboard object from the main application screen and then tie in copy and paste handlers for the mouse clicks: During initialization I assign the system clipboard: clippy = Toolkit.getDefaultToolkit().getSystemClipboard(); Copy Handler Node copyNode = ((CLIInfo) node.getUserObject()).DOMNode.cloneNode(true); NodeCopyPaste contents = new NodeCopyPaste(copyNode); clippy.setContents (contents, null); Paste Handler Transferable clipboardContent = clippy.getContents (null); Node clonedNode = null; if ((clipboardContent != null) && (clipboardContent.isDataFlavorSupported (NodeCopyPaste.NodeFlavor))) { try { NodeCopyPaste tempNCP = (NodeCopyPaste) clipboardContent.getTransferData (NodeCopyPaste.NodeFlavor); clonedNode = tempNCP.aNode.cloneNode(true); } catch (Exception e) { e.printStackTrace (); } Thanks!

    Read the article

  • Force copy files off CRC error filled hard drive

    - by TheLakersHighlights
    So I got a dying Western Digital hard drive here and I have a new Western Digital hard drive to transfer all the data to. I have the new HDD hooked up by a SATA to USB. I want to transfer all the pictures, etc to the new HDD. I am unable to because of the CRC error. I have ran chkdsk /f /r and it didnt work because the drive is just simply dying. What tool will let me bypass CRC and continue on with the copying? OS: Vista Home Prem. 32bit

    Read the article

  • Copy .exe to Explorer.exe!

    - by Phillip
    What would happen if an ordinary .exe file is copied to explorer.exe? Will it be automatically running as long as explorer.exe is running? This seems like a major security whole...is it even possible? Does anti-virus protect against that sort of thing?

    Read the article

  • What do different patterns mean in Windows 8 file copy dialog

    - by MainMa
    When copying or extracting files, Windows 8 shows the chart with the speed of the operation. I noticed several patterns: Randomness, High speed at the beginning, then low speed during the most part of the operation, Mostly constant speed. 1. Randomness/nice mountains. 2. High speed at the beginning, then low speed during the most part of the operation. 3. Low speed at the beginning, then high speed during the most part of the operation. (Similar to the previous image, but inverted) 3. Mostly constant speed. (Same as previous image, but without the fast start) I'm curious, what each of those patterns mean? Do some indicate that there may be a problem with hard disk performance? Why the nearly constant speed is so rare, even when copying a single large file from and to a spinning drive, or when copying a single large file or a bunch of small files from and to an SSD?

    Read the article

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