Search Results

Search found 45620 results on 1825 pages for 'derived class'.

Page 9/1825 | < Previous Page | 5 6 7 8 9 10 11 12 13 14 15 16  | Next Page >

  • gcc returns error with nested class

    - by Nate
    Howdy, I am attempting to use the fully qualified name of my nested class as below, but the compiler is balking! template <class T> class Apple { //constructors, members, whatevers, etc... public: class Banana { public: Banana() { //etc... } //other constructors, members, etc... }; }; template <class K> class Carrot{ public: //etc... void problemFunction() { Apple<int>::Banana freshBanana = someVar.returnsABanana(); //line 85 giveMonkey(freshBanana); //line 86 } }; My issue is, the compiler says: Carrot.h:85: error: expected ';' before 'freshBanana' Carrot.h:86: error: 'freshBanana' was not declared in this scope I had thought that using the fully qualified name permitted me to access this nested class? It's probably going to smack me in the face, but what on earth am I not seeing here??

    Read the article

  • Objective-C: Getting the True Class of Classes in Class Clusters

    - by TechZen
    Recently while trying to answer a questions here, I ran some test code to see how Xcode/gdb reported the class of instances in class clusters. (see below) In the past, I've expected to see something like: PrivateClusterClass:PublicSuperClass:NSObject Such as this (which still returns as expected): NSPathStore2:NSString:NSObject ... for a string created with +[NSString pathWithComponents:]. However, with NSSet and subclass the following code: - (void)applicationDidFinishLaunching:(UIApplication *)application { NSSet *s=[NSSet setWithObject:@"setWithObject"]; NSMutableSet *m=[NSMutableSet setWithCapacity:1]; [m addObject:@"Added String"]; NSMutableSet *n = [[NSMutableSet alloc] initWithCapacity:1]; [self showSuperClasses:s]; [self showSuperClasses:m]; [self showSuperClasses:n]; [self showSuperClasses:@"Steve"]; } - (void) showSuperClasses:(id) anObject{ Class cl = [anObject class]; NSString *classDescription = [cl description]; while ([cl superclass]) { cl = [cl superclass]; classDescription = [classDescription stringByAppendingFormat:@":%@", [cl description]]; } NSLog(@"%@ classes=%@",[anObject class], classDescription); } ... outputs: // NSSet *s NSCFSet classes=NSCFSet:NSMutableSet:NSSet:NSObject //NSMutableSet *m NSCFSet classes=NSCFSet:NSMutableSet:NSSet:NSObject //NSMutableSet *n NSCFSet classes=NSCFSet:NSMutableSet:NSSet:NSObject // NSString @"Steve" NSCFString classes=NSCFString:NSMutableString:NSString:NSObject The debugger shows the same class for all Set instances. I know that in the past the Set class cluster did not return like this. What has changed? (I suspect it is a change in the bridge from Core Foundation.) What class cluster report just a generic class e.g. NSCFSet and which report an actual subclass e.g. NSPathStore2? Most importantly, when debugging how do you determine the actual class of a NSSet cluster instance?

    Read the article

  • Why can't my main class see the array in my calender class

    - by Rocky Celltick Eadie
    This is a homework problem. I'm already 5 days late and can't figure out what I'm doing wrong.. this is my 1st semester in Java and my first post on this site Here is the assignment.. Create a class called Calendar. The class should contain a variable called events that is a String array. The array should be created to hold 5 elements. Use a constant value to specify the array size. Do not hard code the array size. Initialize the array in the class constructor so that each element contains the string “ – No event planned – “. The class should contain a method called CreateEvent. This method should accept a String argument that contains a one-word user event and an integer argument that represents the day of the week. Monday should be represented by the number 1 and Friday should be represented by the number 5. Populate the events array with the event info passed into the method. Although the user will input one-word events, each event string should prepend the following string to each event: event_dayAppoinment: (where event_day is the day of the week) For example, if the user enters 1 and “doctor” , the first array element should read: Monday Appointment: doctor If the user enters 2 and “PTA” , the second array element should read: Tuesday Appointment: PTA Write a driver program (in a separate class) that creates and calls your Calendar class. Then use a loop to gather user input. Ask for the day (as an integer) and then ask for the event (as a one word string). Pass the integer and string to the Calendar object’s CreateEvent method. The user should be able enter 0 – 5 events. If the user enters -1, the loop should exit and your application should print out all the events in a tabular format. Your program should not allow the user to enter invalid values for the day of the week. Any input other than 1 – 5 or -1 for the day of the week would be considered invalid. Notes: When obtaining an integer from the user, you will need to use the nextInt() method on your Scanner object. When obtaining a string from a user, you will need to use the next() method on your Scanner object. Here is my code so far.. //DRIVER CLASS /** * * @author Rocky */ //imports scanner import java.util.Scanner; //begin class driver public class driver { /** * @paramargs the command line arguments */ //begin main method public static void main(String[] args) { //initiates scanner Scanner userInput = new Scanner (System.in); //declare variables int dayOfWeek; String userEvent; //creates object for calender class calendercalenderObject = new calender(); //user prompt System.out.println("Enter day of week for your event in the following format:"); System.out.println("Enter 1 for Monday"); System.out.println("Enter 2 for Tuesday"); System.out.println("Enter 3 for Wednsday"); System.out.println("Enter 4 for Thursday"); System.out.println("Enter 5 for Friday"); System.out.println("Enter -1 to quit"); //collect user input dayOfWeek = userInput.nextInt(); //user prompt System.out.println("Please type in the name of your event"); //collect user input userEvent = userInput.next(); //begin while loop while (dayOfWeek != -1) { //test for valid day of week if ((dayOfWeek>=1) && (dayOfWeek<=5)){ //calls createEvent method in calender class and passes 2 variables calenderObject.createEvent(userEvent,dayOfWeek); } else { //error message System.out.println("You have entered an invalid number"); //user prompts System.out.println("Press -1 to quit or enter another day"); System.out.println("Enter 1 for Monday"); System.out.println("Enter 2 for Tuesday"); System.out.println("Enter 3 for Wednsday"); System.out.println("Enter 4 for Thursday"); System.out.println("Enter 5 for Friday"); System.out.println("Enter -1 to quit"); //collect user input dayOfWeek = userInput.nextInt(); //end data validity test } //end while loop } //prints array to screen int i=0; for (i=0;i<events.length;i++){ System.out.println(events[i]); } //end main method } } /** * * @author Rocky */ //imports scanner import java.util.Scanner; //begin calender class public class calender { //creates events array String[] events = new String[5]; //begin calender class constructor public calender() { //Initializes array String[] events = {"-No event planned-","-No event planned-","-No event planned-","-No event planned-","-No event planned-"}; //end calender class constructor } //begin createEvent method public String[] createEvent (String userEvent, int dayOfWeek){ //Start switch test switch (dayOfWeek){ case 1: events[0] = ("Monday Appoinment:") + userEvent; break; case 2: events[1] = ("Tuesday Appoinment:") + userEvent; break; case 3: events[2] = ("WednsdayAppoinment:") + userEvent; break; case 4: events[3] = ("Thursday Appoinment:") + userEvent; break; case 5: events[4] = ("Friday Appoinment:") + userEvent; break; default: break; //End switch test } //returns events array return events; //end create event method } //end calender class }

    Read the article

  • Cast MyEntity To LinqEntity throw a base controller class

    - by Mohammad Kani
    hi there i design a multilayer we appliction andusing LINQ a my data provider i need to user my own Entites instead o LINQ etities. so i created Entities Project and create my entities in it. when i get data from contex and cast them to my entities , everything is ok. but when i want to cast on of my entities to linq entity , an exception thrown. in my linq entity i add CTYPE operator from and to my entities Exp : Public Class BaseController(Of LinqEntity As {BaseEntity, New}, MyEntity As ModuleEntities.BaseEntityInfo) Implements Interfaces.Base(Of ServiceEntity) 'This methd work fine and cast LinqEntity to MyEntity Public Function GetAll() As List(Of MyEntity ) Dim q = (From x In Context.GetTable(Of LinqEntity)() _ Select x).Cast(Of MyEntityBase) End Function Public Sub Update(ByVal entity As MyEntity) 'here is problem 'cast , direct cast , or anything not work Dim x as LinqEntity = entity Me.Context.GetTable(Of LinqEntity).InsertOnSubmit(entity) Me.Context.SubmiChanges() End Sub

    Read the article

  • Interface and base class mix, the right way to implement this

    - by Lerxst
    I have some user controls which I want to specify properties and methods for. They inherit from a base class, because they all have properties such as "Foo" and "Bar", and the reason I used a base class is so that I dont have to manually implement all of these properties in each derived class. However, I want to have a method that is only in the derived classes, not in the base class, as the base class doesn't know how to "do" the method, so I am thinking of using an interface for this. If i put it in the base class, I have to define some body to return a value (which would be invalid), and always make sure that the overriding method is not calling the base. method Is the right way to go about this to use both the base class and an interface to expose the method? It seems very round-about, but every way i think about doing it seems wrong... Let me know if the question is not clear, it's probably a dumb question but I want to do this right.

    Read the article

  • How to make some functions of a class as private for third level of inheritance.

    - by Shantanu Gupta
    I have created a class say A which has some functions defined as protected. Now Class B inherits A and class C inherits B. Class A has private default constructor and protected parameterized constructor. I want Class B to be able to access all the protected functions defined in Class A but class C can have access on some of the functions only not all the functions and class C is inheriting class B. How can I restrict access to some of the functions of Class A from Class C ? Class A { private A(){} protected A(int ){} protected calc(){} protected allow(){} } Class B : A {} // calc() and allow() should be accessible here CLass C:B { // calc() should not be accessible here but allow() should be accessible here. }

    Read the article

  • calling members of class to another class

    - by Hussain
    hii every one I m using Applets i ve three classes ie three applets and I need some members(variables) of one class into another class when i m trying to access variables from one class to another class by creating of object of called class in to calling class then it doesnt give wright output it access those variables but gives null or zero values

    Read the article

  • Having a base class function depend on its child class C#

    - by Junk Junk
    I have a Base class with a method that a child class will almost always override. However, instead of replacing the base class' method entirely, I would like for whatever is derived in the child class to be added to what is already in the base class. For Example: class BaseClass public string str() { var string = "Hello my name is" ; } class ChildClass : BaseClass public override string str(){ var string = "Sam"; } The point is that if I want to access the str() method by creating an instance of the ChildClass, the string will print out as "Hello, my name is Sam". I've been looking around and all I have been finding is that this should NOT happen, as the base class shouldn't even know that it is being inherited. So, if the design is false, how would I go about doing this? Keep in mind that there will be multiple child classes inheriting from BaseClass. Thank you

    Read the article

  • choose the best class if 2 class have same P (c|d), naive bayes

    - by ryandi
    Hello I have some question about naive bayes classifier . In my project I have to classify a text into a class from 4 available class. In naive bayes we have formula like cmap=argmax.P(d|c).P(c) I have standarize the amount of training document of each class, so I got a same P(c) value for each class (0.25). Here's my question: What if a testing document token doesn't have any token which belong to any of those 4 class(in document training)? Resulted to all of the class have same value of P(d|c).P(c). Which class should i pick? What if the token exist, and 2 class or more have same value of P(d|c).P(c) what should I do? Thank you..

    Read the article

  • defining information out of class

    - by calccrypto
    is there a way to define a value within a class in the __init__ part, send it to some variable outside of the class without calling another function within the class? like class c: def __init__(self, a): self.a = a b = 4 # do something like this so that outside of class c, # b is set to 4 automatically when i use class c def function(self): ... # whatever. this doesnt matter i have multiple classes that have different values for b. i could just make a list that tells the computer to change b, but i would rather set b within each class

    Read the article

  • Class Method not working in objective c

    - by byteSlayer
    In my code I have a class called 'ProfileShareViewController', In which I have imported another class I have created called 'OwnProfileData', And I have also created an Instance of that class (class = OwnProfileData) as a property Of 'ProfileShareViewController' and synthesized it (instance called 'OwnProfile'). In another class I have called 'EditProfileViewController', I have imported the 'ProfileShareViewController', and now I am trying to change a property of the OwnProfile object from the ProfileShareViewController within the EditProfileViewController class. For some reason that doesn't work. I have Tried typing: [[ProfileShareViewController ownProfile] setName:@"Ido"]; (The property I am trying to set is Name, and as it is synthesized in OwnProfileData, I am using 'setName'). This doesn't work and I get the warning: "No known class method for selector 'ownMethod'. Any Idea as for why that might happen and how I can fix this? Thanks for your comments! Any support is highly appreciated!

    Read the article

  • Should all public methods in an abstract class be marked virtual?

    - by Justin Pihony
    I recently had to update an abstract base class on some OSS that I was using so that it was more testable by making them virtual (I could not use an interface as it combined two). This got me thinking whether I should mark all of the methods that I needed virtual, or if I should mark every public method/property virtual. I generally agree with Roy Osherove that every method should be made virtual, but I came across this article that got me thinking about whether this was necessary or not. I am going to limit this down to abstract classes for simplicity, however (whether all concrete public methods should be virtual is especially debatable, I am sure). I could see where you might want to allow a sub-class to use a method, but not want it overriding the implementation. However, as long as you trust that Liskov's Substitution Principle will be followed, then why would you not allow it to be overriden? By marking it abstract, you are forcing a certain override anyway, so, it seems to me that all public methods inside of an abstract class should indeed be marked virtual. However, I wanted to ask in case there was something I might not be thinking. Should all public methods within an abstract class be made virtual?

    Read the article

  • Significant amount of the time, I can't think of a reason to have an object instead of a static class. Do objects have more benefits than I think?

    - by Prog
    I understand the concept of an object, and as a Java programmer I feel the OO paradigm comes rather naturally to me in practice. However recently I found myself thinking: Wait a second, what are actually the practical benefits of using an object over using a static class (with proper encapsulation and OO practices)? I could think of two benefits of using an object (both significant and powerful): Polymorphism: allows you to swap functionality dynamically and flexibly during runtime. Also allows to add new functionality 'parts' and alternatives to the system easily. For example if there's a Car class designed to work with Engine objects, and you want to add a new Engine to the system that the Car can use, you can create a new Engine subclass and simply pass an object of this class into the Car object, without having to change anything about Car. And you can decide to do so during runtime. Being able to 'pass functionality around': you can pass an object around the system dynamically. But are there any more advantages to objects over static classes? Often when I add new 'parts' to a system, I do so by creating a new class and instantiating objects from it. But recently when I stopped and thought about it, I realized that a static class would do just the same as an object, in a lot of the places where I normally use an object. For example, I'm working on adding a save/load-file mechanism to my app. With an object, the calling line of code will look like this: Thing thing = fileLoader.load(file); With a static class, it would look like this: Thing thing = FileLoader.load(file); What's the difference? Fairly often I just can't think of a reason to instantiate an object when a plain-old static-class would act just the same. But in OO systems, static classes are fairly rare. So I must be missing something. Are there any more advantages to objects other from the two that I listed? Please explain.

    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

  • SQL Server Integration Services 2008: Importing Excel Data Using Derived Column Transformation

    The complexity involved in transferring data between Excel and SQL Server results from different and sometimes incompatible data types. The Import and Export wizard mitigates potential issues introduced by these incompatibilities by taking advantage of Data Conversion Transformation. Marcin Policht describes another approach that produces an equivalent outcome by employing Derived Column Transformation instead.

    Read the article

  • Is there a good design pattern for this messaging class?

    - by salonMonsters
    Is there a good design pattern for this? I want to create a messaging class. The class will be passed: the type of message (eg. signup, signup confirmation, password reminder etc) the client's id The class needs to then look up the client's messaging preferences in the db (whether they want communication by email, sms or both) Then depending on the client's preference it will format the message for the medium (short version for sms, long form for email) and send it through our mail or sms provider's API. Because the fact that we want to be able to change out email and sms providers if need be I wondered if the Command Pattern would be a good choice.

    Read the article

  • access exception when invoking method of an anonymous class using java reflection

    - by Asaf David
    Hello I'm trying to use an event dispatcher to allow a model to notify subscribed listeners when it changes. the event dispatcher receives a handler class and a method name to call during dispatch. the presenter subscribes to the model changes and provide a Handler implementation to be called on changes. Here's the code (I'm sorry it's a bit long). EventDispacther: package utils; public class EventDispatcher<T> { List<T> listeners; private String methodName; public EventDispatcher(String methodName) { listeners = new ArrayList<T>(); this.methodName = methodName; } public void add(T listener) { listeners.add(listener); } public void dispatch() { for (T listener : listeners) { try { Method method = listener.getClass().getMethod(methodName); method.invoke(listener); } catch (Exception e) { System.out.println(e.getMessage()); } } } } Model: package model; public class Model { private EventDispatcher<ModelChangedHandler> dispatcher; public Model() { dispatcher = new EventDispatcher<ModelChangedHandler>("modelChanged"); } public void whenModelChange(ModelChangedHandler handler) { dispatcher.add(handler); } public void change() { dispatcher.dispatch(); } } ModelChangedHandler: package model; public interface ModelChangedHandler { void modelChanged(); } Presenter: package presenter; public class Presenter { private final Model model; public Presenter(Model model) { this.model = model; this.model.whenModelChange(new ModelChangedHandler() { @Override public void modelChanged() { System.out.println("model changed"); } }); } } Main: package main; public class Main { public static void main(String[] args) { Model model = new Model(); Presenter presenter = new Presenter(model); model.change(); } } Now, I except to get the "model changed" message. However, I'm getting an java.lang.IllegalAccessException: Class utils.EventDispatcher can not access a member of class presenter.Presenter$1 with modifiers "public". I understand that the class to blame is the anonymous class i created inside the presenter, however I don't know how to make it any more 'public' than it currently is. If i replace it with a named nested class it seem to work. It also works if the Presenter and the EventDispatcher are in the same package, but I can't allow that (several presenters in different packages should use the EventDispatcher) any ideas?

    Read the article

  • Cocoa class not displaying data in NSWindow

    - by Matt S.
    I have one class that controls one window, and another class that controls a different window in the same xib, however, the second window never displays what it should. In the first class I alloc and init the second class, then pass some information to it. In the second class it displays that data in the table view. Yes, in the .xib I have all the connections set up correctly, I've quadruple checked. Also the code is correct, same with the connections, I've quadruple checked.

    Read the article

  • PHP object class variable

    - by mck89
    I have built a class in PHP and I must declare a class variable as an object. Everytime I want to declare an empty object I use: $var=new stdClass; But if I use it to declare a class variable as class foo { var $bar=new stdClass; } a parse error occurs. Is there a way to do this or must I declare the class variable as an object in the constructor function? PS: I'm using PHP 4.

    Read the article

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