imgregduh's Profile User Rating: -----

Reputation: 0 Apprentice
Active Members
Active Posts:
57 (0.05 per day)
15-May 11
Profile Views:
Last Active:
User is offline Feb 04 2013 02:19 PM

Previous Fields

Dream Kudos:
Icon   imgregduh has not set their status

Posts I've Made

  1. In Topic: "@help" function; maybe threading ?

    Posted 3 Feb 2013

    View PostSkydiver, on 03 February 2013 - 05:06 PM, said:

    If you are changing the code substantially, you should have posted a reply and not changed your original post because it breaks the continuity of the thread for any late comers to this thread.

    Anyway you are trying to get input both on line 11 and line 26. I don't think that the standard C++ input is thread-safe, nor will it work the way you are expecting it to. It seems that you are assuming that the C++ library will coalesce the two input calls, and that somehow it will magically determine which one of the input readers will run and choke off the other one.

    undefined behaviour's recommendation is still the most appropriate. Only do input and parsing from one thread. If you really want to go multi-threaded execution of actions, start the action after the input and parsing.

    alright throwing the threading idea out of the picture,
    let me try to draw a picture to describe what i am talking about

    ask user question expecting string input->
    enter input in console ->
    checks the string for certain word ->
    if string passes ignore previous function ->
    enter into function that originally asked the question

    lets say the function that is asking the question only wants a single string to be taken in

    im trying to avoid placing a conditional statement around all the input locations in my entire program just to look for one word


    found a possible solution
    class MyCin
        MyCin& operator>> (std::string rhs)
                std::cin >> rhs;
                if (rhs == "/help")
                    std::cout << "Help message";
            return *this;

    overload the operator>> for it to check for "/help" then continue after the check
  2. In Topic: "@help" function; maybe threading ?

    Posted 3 Feb 2013

    View Postundefined behaviour, on 03 February 2013 - 07:30 AM, said:

    This testcase is incomplete; We can't reproduce the problem you're experiencing.

    Perhaps it might be a better idea to design your console application as a single-threaded one, and then use your profiler to determine where to expose parallelism. Not only will you have less debugging to do, but you will also be able to make useful statements regarding the optimisation you've done, rather than guessing and not quite targetting it correctly.

    i simplified the example for it to ask a simple question and wait for an input.

    in the example, i ran it and i have to input for the help function and for the input in the main function im trying avoid entering the information twice and only have one input go through each function once

    at the moment with the given code avoid if i enter "something" as input i have to do it twice for it to be entered. the first somone is being inputted into the help function then the second one is being taken in for the main function
  3. In Topic: question spawning list of objects

    Posted 18 Nov 2012

    View PostXupicor, on 17 November 2012 - 01:44 AM, said:

    Do you really need it anywhere? Remember, it's a vector of instances. So, do you ever need an instance of Item base class? If not, why not let the compiler check at least for those compile-time mishaps for you, by making it ABC (abstract base class).

    my original idea was item as the base abstract class only having a few variables like name, id, goldvalue with their respective get and set functions and the additional of a virtual display function. while consumables would have health and mana value. also weapons and armor with stuff like attack mattack defense mdefense. Items would be derived to consumables and equipment then equipment will derive to weapons and armors. The thing i couldnt figure out was how to store and call the consumables and equipment that would be defined already. Like where to define Small health potion that heals for 100 health and call it to use it.
  4. In Topic: question spawning list of objects

    Posted 16 Nov 2012

    View PostSkydiver, on 16 November 2012 - 07:18 PM, said:

    The offending code:

    View Postimgregduh, on 16 November 2012 - 08:21 PM, said:

    void Consumable::Consume(Character& C,vector<Item> invent,Consumable item)

    it was complying with that there after i added a {return T_INVALID;} to this line virtual ItemType getItemType() const {return T_INVALID;}

    and i removed this vector<Item> invent from that function above afterwards since i realize i dont even need that there.
  5. In Topic: question spawning list of objects

    Posted 16 Nov 2012

    View Postbaavgai, on 16 November 2012 - 06:36 AM, said:

    Look at the error:
    cannot instantiate abstract class due to following members: Item::ItemType Item::getItemType(void) const

    This makes sense because of the abstract funciton: virtual ItemType getItemType() const = 0;

    Why do we have an abstract function? Because Item is a base class and instances of Item may not make sense. If they do, you can fix it by implementing the method and making it non abstract.

    While the error is in vector<Item>, you'd have the same problem with Item foo;. Essentially, you can't make a concrete object of type Item, but type Item * is fine.

    Strangely, this is one of the reasons I used an abstract class, because a something like vector<Item> would be useless if you really wanted to get a child type out of it. By strongly constraining your types, you prevent yourself making type errors at compile time.

    my experience in this particular error is very slim,
    im still not sure what to put to make it non abstract

    EDIT: nvm i just put this virtual ItemType getItemType() const {return T_INVALID;} and it compiled

My Information

Member Title:
D.I.C Head
Age Unknown
Birthday Unknown

Contact Information



imgregduh hasn't added any friends yet.


imgregduh has no profile comments yet. Why not say hello?