Search Results

Search found 3493 results on 140 pages for 'constructor'.

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

  • Constructor type not found

    - by WaffleTop
    Hello, What I am doing: I am taking the Microsoft Enterprise Library 4.1 and attempting to expand upon it using a few derived classes. I have created a MyLogEntry, MyFormatter, and MyTraceListener which derive from their respective base classes when you remove the "My" from their names. What my problem is: Everything compiles fine. When I go to run a test using Logger.Write(logEntry) it errors right after it initializes MyTraceListener with an error message: "The current build operation (... EnterpriseLibrary.Logging.LogWriter, null]) failed: Constructor on type 'MyLogging.MyFormatter' not found. (Strategy type ConfiguredObjectStrategy, index 2) I figured it was something to do with the constructor so I tried removing it, add it, and adding a call to the base class LogFormatter. Nothing has worked. Does anyone have insight into this problem? Is it maybe a reference issue? Bad App.config configuration? Thank you in advance

    Read the article

  • ASP.NET MVC - ASPX with non-default constructor

    - by bh213
    Is it possible for a ASPX view (in ASP.NET MVC) to have non-default constructor AND use this constructor when creating this view? Example - Page will inherit from this class: public class ViewPageWithHelper<TModel> : System.Web.Mvc.ViewPage<TModel> where TModel : class { public ViewPageWithHelper(Helpers helpers) { Helpers = helpers; } protected Helpers Helpers { get; private set; } } ASPX view: <%@ Page Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="MyInjectedViewPage<MyModel>" %> <% Helpers.XXXX %> Now, I'd like to inject Helpers into view somehow - automatically. Ideas?

    Read the article

  • Flash AS3: automate property assignment to new instance from arguments in constructor

    - by matt lohkamp
    I like finding out about tricky new ways to do things. Let's say you've got a class with a property that gets set to the value of an argument in the constructor, like so: package{ public class SomeClass{ private var someProperty:*; public function SomeClass(_someProperty:*):void{ someProperty = _someProperty; } } } That's not exactly a hassle. But imagine you've got... I don't know, five properties. Ten properties, maybe. Rather then writing out each individual assignment, line by line, isn't there a way to loop through the constructor's arguments and set the value of each corresponding property on the new instance accordingly? I don't think that the ...rest or arguments objects will work, since they only keep an enumerated list of the arguments, not the argument names - I'm thinking something like this would be better: for(var propertyName:String in argsAsAssocArray){this[propertyName] = argsAsAssocArray[propertyName];} ... does something like this exist?

    Read the article

  • How to use this Color's constructor? Java

    - by MaxMackie
    According to Oracle's site, the class Color has a constructor that accepts a single int value which represents an RGB value. http://download.oracle.com/javase/1.4.2/docs/api/java/awt/Color.html#Color(int) An RGB color is actually three different numbers ranging from 0-255. So combining them together to make one int would look like this: White 255,255,255 White 255255255 Right? So I pass this to the constructor and get a vibrant teal color. What am I doing wrong? What haven't I understood?

    Read the article

  • C++ Why is the copy constructor implicitly called?

    - by ShaChris23
    Why is the Child class's copy constructor called in the code below? I mean, it automatically converts Base to Child via the Child copy constructor. The code below compiles, but shouldn't it not compile since I haven't provided bool Child::operator!=(Base const&)? class Base { }; class Child : public Base { public: Child() {} Child(Base const& base_) : Base(base_) { std::cout <<"should never called!"; } bool operator!=(Child const&) { return true; } }; void main() { Base base; Child child; if(child != base) std::cout << "not equal"; else std::cout << "equal"; }

    Read the article

  • std::string constructor corrupts pointer

    - by computergeek6
    I have an Entity class, which contains 3 pointers: m_rigidBody, m_entity, and m_parent. Somewhere in Entity::setModel(std::string model), it's crashing. Apparently, this is caused by bad data in m_entity. The weird thing is that I nulled it in the constructor and haven't touched it since then. I debugged it and put a watchpoint on it, and it comes up that the m_entity member is being changed in the constructor for std::string that's being called while converting a const char* into an std::string for the setModel call. I'm running on a Mac, if that helps (I think I remember some problem with std::string on the Mac). Any ideas about what's going on?

    Read the article

  • Static constructor can run after the non-static constructor. Is this a compiler bug?

    - by Joe H
    The output from the following program is: Non-Static Static Non-Static Is this a compiler bug? I expected: Static Non-Static Non-Static because I thought the static constructor was ALWAYS called before the non-static constructor. I tested this with Visual Studio 2010 using both .net 3.5 and .net 4.0. using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace StaticConstructorBug { class Program { static void Main(string[] args) { var mc = new MyClass(); Console.ReadKey(); } } public class MyClass { public MyClass() { Console.WriteLine("Non-static"); } static MyClass() { Console.WriteLine("Static"); } public static MyClass aVar = new MyClass(); } }

    Read the article

  • C++ Scoping and ambiguity in constructor overloads

    - by loarabia
    I've tried the following code snippet in 3 different compilers (G++, clang++, CL.exe) and they all report to me that they cannot disambiguate the overloaded constructors. Now, I know how I could modify the call to the constructor to make it pick one or the other (either make explicit that the second argument is a unsigned literal value or explicitly cast it). However, I'm curious why the compiler would be attempting to choose between constructors in the first place given that one of the constructors is private and the call to the constructor is happening in the main function which should be outside the class's scope. Can anyone enlighten me? class Test { private: Test(unsigned int a, unsigned int *b) { } public: Test(unsigned int a, unsigned int b) { } }; int main() { Test t1 = Test(1,0); // compiler is confused }

    Read the article

  • Why do we need a private constructor?

    - by isthatacode
    if a class has a private constructor then it cant be instantiated. so, if i dont want my class to be instantiated and still use it, then i can make it static. what is the use of a private constructor ? Also its used in singleton class, except that, is there any othe use ? (Note : The reason i am excuding the singleton case above is because I dont understand why do we need a singleton at all ? when there is a static class availble. You may not answer for my this confusion in the question. )

    Read the article

  • this pointer to base class constructor?

    - by Rolle
    I want to implement a derived class that should also implement an interface, that have a function that the base class can call. The following gives a warning as it is not safe to pass a this pointer to the base class constructor: struct IInterface { void FuncToCall() = 0; }; struct Base { Base(IInterface* inter) { m_inter = inter; } void SomeFunc() { inter->FuncToCall(); } IInterface* m_inter; }; struct Derived : Base, IInterface { Derived() : Base(this) {} FuncToCall() {} }; What is the best way around this? I need to supply the interface as an argument to the base constructor, as it is not always the dervied class that is the interface; sometimes it may be a totally different class. I could add a function to the base class, SetInterface(IInterface* inter), but I would like to avoid that.

    Read the article

  • question about copy constructor

    - by lego69
    I have this class: class A { private: int player; public: A(int initPlayer = 0); A(const A&); A& operator=(const A&); ~A(); void foo() const; }; and I have function which contains this row: A *pa1 = new A(a2); can somebody please explain what exactly is going on, when I call A(a2) compiler calls copy constructor or constructor, thanks in advance

    Read the article

  • Passing parameters to a delphi TFrame

    - by ajob
    To avoid singletons and global variables I'd like to be able to pass parameters to a TFrame component. However since a TFrame normally is included on form at design time it is only possible to use the default constructor. The parent form can of course set some properties in the OnCreate callback after the TFrame has been created. However this does not ensure that a property is not forgotten, and the dependencies are not as clear as using a constructor. A nice way would be if it was possible to register a factory for creating components while the dfm file is being read. Then the required parameters could be passed to the TFrame constructor when created by the factory. Is there a way of accomplishing this? Or does anyone have a better solution on how to pass parameters to a TFrame?

    Read the article

  • How to call superconstructor in a neat way

    - by sandis
    So here is my code: public MyClass (int y) { super(y,x,x); //some code } My problem is that in this case i want to generate a 'x' and sent to the super constructor. However the call to the superconstructor must be the first line in this constructor. Of course I could do something like this: int x; { x = generateX(); } But this feels ugly, and then the code will run no matter what constructor I use, which feels not so nice. Right now I am consider encapsulating my whole object in another object that only calculates x and then starts this object. Is this the best approach?

    Read the article

  • Explicitly typing variables causes compiler to think an instance of a builtin type doesn't have a pr

    - by wallacoloo
    I narrowed the causes of an AS3 compiler error 1119 down to code that looks similar to this: var test_inst:Number = 2.953; trace(test_inst); trace(test_inst.constructor); I get the error "1119: Access of possibly undefined property constructor through a reference with static type Number." Now if I omit the variable's type, I don't get that error: var test_inst = 2.953; trace(test_inst); trace(test_inst.constructor); it produces the expected output: 2.953 [class Number] So what's the deal? I like explicitly typing variables, so is there any way to solve this error other than not providing the variable's type?

    Read the article

  • Custom constructors for models in Google App Engine (python)

    - by Nikhil Chelliah
    I'm getting back to programming for Google App Engine and I've found, in old, unused code, instances in which I wrote constructors for models. It seems like a good idea, but there's no mention of it online and I can't test to see if it works. Here's a contrived example, with no error-checking, etc.: class Dog(db.Model): name = db.StringProperty(required=True) breeds = db.StringListProperty() age = db.IntegerProperty(default=0) def __init__(self, name, breed_list, **kwargs): db.Model.__init__(**kwargs) self.name = name self.breeds = breed_list.split() rufus = Dog('Rufus', 'spaniel terrier labrador') rufus.put() The **kwargs are passed on to the Model constructor in case the model is constructed with a specified parent or key_name, or in case other properties (like age) are specified. This constructor differs from the default in that it requires that a name and breed_list be specified (although it can't ensure that they're strings), and it parses breed_list in a way that the default constructor could not. Is this a legitimate form of instantiation, or should I just use functions or static/class methods? And if it works, why aren't custom constructors used more often?

    Read the article

  • Constructors with inheritance in c++

    - by Crystal
    If you have 3 classes, with the parent class listed first shape- 2d shapes, 3d shapes - circle, sphere When you write your constructor for the circle class, would you ever just initialize the parent Shape object and then your current object, skipping the middle class. It seems to me you could have x,y coordinates for Shape and initialize those in the constructor, and initialize a radius in the circle or sphere class, but in 2d or 3d shape classes, I wouldn't know what to put in the constructor since it seems like it would be identical to shape. So is something like this valid Circle::Circle(int x, int y, int r) : Shape(x, y), r(r) {} I get a compile error of: illegal member initialization: 'Shape' is not a base or member So I wasn't sure if my code was legal or best practice even. Or if instead you'd have the middle class just do what the top level Shape class does TwoDimensionalShape::TwoDimensionalShape(int x, int y) : Shape (x, y) {} and then in the Circle class Circle::Circle(int x, int y, int r) : TwoDimensionalShape(x, y), r(r) {}

    Read the article

  • How to make the constructor for the following exercise in c++?

    - by user40630
    This is the exercise I?m trying to solve. It's from C++, How to program book from Deitel and it's my homework. (Card Shuffling and Dealing) Create a program to shuffle and deal a deck of cards. The program should consist of class Card, class DeckOfCards and a driver program. Class Card should provide: a) Data members face and suit of type int. b) A constructor that receives two ints representing the face and suit and uses them to initialize the data members. c) Two static arrays of strings representing the faces and suits. d) A toString function that returns the Card as a string in the form “face of suit.” You can use the + operator to concatenate strings. Class DeckOfCards should contain: a) A vector of Cards named deck to store the Cards. b) An integer currentCard representing the next card to deal. c) A default constructor that initializes the Cards in the deck. The constructor should use vector function push_back to add each Card to the end of the vector after the Card is created and initialized. This should be done for each of the 52 Cards in the deck. d) A shuffle function that shuffles the Cards in the deck. The shuffle algorithm should iterate through the vector of Cards. For each Card, randomly select another Card in the deck and swap the two Cards. e) A dealCard function that returns the next Card object from the deck. f) A moreCards function that returns a bool value indicating whether there are more Cards to deal. The driver program should create a DeckOfCards object, shuffle the cards, then deal the 52 cards. The problem I'm facing is that I don't know exactly how to make the constructor for the second class. See description commented in the code bellow. #include <iostream> #include <vector> using namespace std; /* * */ //Class card. No problems here. class Card { public: Card(int, int); string toString(); private: int suit, face; static string faceNames[13]; static string suitNames[4]; }; string Card::faceNames[13] = {"Ace","Two","Three","Four","Five","Six","Seven","Eight","Nine","Ten","Queen","Jack","King"}; string Card::suitNames[4] = {"Diamonds","Clubs","Hearts","Spades"}; string Card::toString() { return faceNames[face]+" of "+suitNames[suit]; } Card::Card(int f, int s) :face(f), suit(s) { } /*The problem begins here. This class should create(when and object for it is created) a copy of the vector deck, right? But how exactly are these vector cards be initialized? I'll explain better in the constructor definition bellow.*/ class DeckOfCards { public: DeckOfCards(); void shuffleCards(); Card dealCard(); bool moreCards(); private: vector<Card> deck(52); int currentCard; }; int main(int argc, char** argv) { return 0; } DeckOfCards::DeckOfCards() { //This is where I'm stuck. I can't figure out how to set each of the 52 cards of the vector deck to have a specific suit and face every one of them, by using only the constructor of the Card class. //What you see bellow was one of my attempts to solve this problem but I blocked pretty soon in the middle of it. for(int i=0; i<deck.size(); i++) { deck[i]//....There is no function to set them. They must be set when initialized. But how?? } } For easier reading: http://pastebin.com/pJeXMH0f

    Read the article

  • Java constructor using generic types

    - by user37903
    I'm having a hard time wrapping my head around Java generic types. Here's a simple piece of code that in my mind should work, but I'm obviously doing something wrong. Eclipse reports this error in BreweryList.java: The method initBreweryFromObject() is undefined for the type <T> The idea is to fill a Vector with instances of objects that are a subclass of the Brewery class, so the invocation would be something like: BreweryList breweryList = new BreweryList(BrewerySubClass.class, list); BreweryList.java package com.beerme.test; import java.util.Vector; public class BreweryList<T extends Brewery> extends Vector<T> { public BreweryList(Class<T> c, Object[] j) { super(); for (int i = 0; i < j.length; i++) { T item = c.newInstance(); // initBreweryFromObject() is an instance method // of Brewery, of which <T> is a subclass (right?) c.initBreweryFromObject(); // "The method initBreweryFromObject() is undefined // for the type <T>" } } } Brewery.java package com.beerme.test; public class Brewery { public Brewery() { super(); } protected void breweryMethod() { } } BrewerySubClass.java package com.beerme.test; public class BrewerySubClass extends Brewery { public BrewerySubClass() { super(); } public void androidMethod() { } } I'm sure this is a complete-generics-noob question, but I'm stuck. Thanks for any tips!

    Read the article

  • Keyword 'this'(Me) is not available calling the base constructor

    - by serhio
    In the inherited class I use the base constructor, but can't use class's members calling this base constructor. In this example I have a PicturedLabel that knows it's own color and has a image. A TypedLabel : PictureLabel knows it's type but uses the base color. The (base)image that uses TypedLabel should be colored with the (base)color, however, I can't obtain this color: Error: Keyword 'this' is not available in the current context A workaround? /// base class public class PicturedLabel : Label { PictureBox pb = new PictureBox(); public Color LabelColor; public PicturedLabel() { // initialised here in a specific way LabelColor = Color.Red; } public PicturedLabel(Image img) : base() { pb.Image = img; this.Controls.Add(pb); } } public enum LabelType { A, B } /// derived class public class TypedLabel : PicturedLabel { public TypedLabel(LabelType type) : base(GetImageFromType(type, this.LabelColor)) //Error: Keyword 'this' is not available in the current context { } public static Image GetImageFromType(LabelType type, Color c) { Image result = new Bitmap(10, 10); Rectangle rec = new Rectangle(0, 0, 10, 10); Pen pen = new Pen(c); Graphics g = Graphics.FromImage(result); switch (type) { case LabelType.A: g.DrawRectangle(pen, rec); break; case LabelType.B: g.DrawEllipse(pen, rec); break; } return result; } }

    Read the article

  • Member initialization while using delegated constructor

    - by Anton
    I've started trying out the C++11 standard and i found this question which describes how to call your ctor from another ctor in the same class to avoid having a init method or the like. Now i'm trying the same thing with code that looks like this: hpp: class Tokenizer { public: Tokenizer(); Tokenizer(std::stringstream *lines); virtual ~Tokenizer() {}; private: std::stringstream *lines; }; cpp: Tokenizer::Tokenizer() : expected('=') { } Tokenizer::Tokenizer(std::stringstream *lines) : Tokenizer(), lines(lines) { } But this is giving me the error: In constructor ‘config::Tokenizer::Tokenizer(std::stringstream*)’: /path/Tokenizer.cpp:14:20: error: mem-initializer for ‘config::Tokenizer::lines’ follows constructor delegation I've tried moving the Tokenizer() part first and last in the list but that didn't help. What's the reason behind this and how should i fix it? I've tried moving the lines(lines) to the body with this->lines = lines; instead and it works fine. But i would really like to be able to use the initializer list. Thanks in advance!

    Read the article

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