How can we get SBJSON connectionDidFinishLoading method inside array data in another class?

Generics and toString methods? how do I make a toString() method work with unspecified types?

  • So I'm trying to create a generic ArrayStack ( that is to say an array-stack that can hold any type of data without having to specify etc ) I have a few questions, but let me give an example to illustrate my point: Say I've finished my ArrayStack and I say: ArrayStack myStack = new ArrayStack(); myStack.push ( X ) myStack.push ( Y ) myStack.push ( Z ) myStack.toString(); // now lets assume for a second X, Y and Z are instances of the Vector class. 1) Should my toString method just print out X, Y and Z or should it print out the contents of these vectors? 2)If I just said; string = string + X; Would the name just be added on automatically, or would I get a type-conflict? If so, how would I get around this? 3) Or would X's toString() method be called? if not, How would I check for/access the toString() method of an object passed through a constructor? 4) And finally, what about fundamental data types. How do I convert ints, doubles, longs, chars etc to Strings on the fly, as they're passed into my ArrayStack class? I'm sorry if this is a bit difficult to follow as a question, i'm just trying to get to grips with generics and all the possibilities involved =P thanks so much for your answers if you do manage to decipher my question :)

  • Answer:

    Actually...it's that you're making it out to be 'difficult'. It's very simple really. If you're accepting input from a User where they have to type the input, you're can just accept everything as a string. string userInput = ""; cin >> userInput; From there you can do tests on userInput to see what the person entered. There are C-functions already defined that check to see if a piece of data 'is numeric'. You pass the userInput to it and it will tell you if it is or not. If it is numeric, just convert it to a type double if you need to use it for some math purposes. If you need to convert the double down to an int variable...just do this... int MyIntVariable; MyIntVariable = int ( TheDoubleValue );

Johnny at Yahoo! Answers Visit the source

Was this solution helpful to you?

Related Q & A:

Just Added Q & A:

Find solution

For every problem there is a solution! Proved by Solucija.

  • Got an issue and looking for advice?

  • Ask Solucija to search every corner of the Web for help.

  • Get workable solutions and helpful tips in a moment.

Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.