vividexstance's Profile User Rating: *****

Reputation: 390 Architect
Group:
Expert
Active Posts:
1,349 (1.55 per day)
Joined:
31-December 10
Profile Views:
5,393
Last Active:
User is offline May 20 2013 07:09 AM
Currently:
Offline

Previous Fields

Country:
Who Cares
OS Preference:
Who Cares
Favorite Browser:
Who Cares
Favorite Processor:
Who Cares
Favorite Gaming Platform:
Who Cares
Your Car:
Who Cares
Dream Kudos:
0
Expert In:
C/C++

Latest Visitors

Icon   vividexstance has not set their status

Posts I've Made

  1. In Topic: object function input

    Posted 29 Apr 2013

    If i get what you're asking correctly, then you want to look at function templates. Templates allow one to write "generic" code, where you don't specify a type while writing the function/class. Only when a user uses your code do the types get put in. One thing about templates however is that if you operate on a variable and do some type of operation that that type doesn't allow, you will run into problems. So make sure you document the function by saying what kind of operations it performs so the user knows to use the right types of variables. Here is a simple example of a template function:
    // This function will perform arithmetic operation on the two arguments passed in.
    template<typename T>
    T add(T val1, T val2)
    {
        return val1 + val2;
    }
    
    int main(void)
    {
        short s1 = 1, s2 = 2;
        int i1 = 4, i2 = 5;
        long l1 = 6, l2 = 7;
    
        cout << s1 << " + " << s2 << " = " << add(s1, s2) << endl;
        cout << i1 << " + " << i2 << " = " << add(i1, i2) << endl;
        cout << l1 << " + " << l2 << " = " << add(l1, l2) << endl;
    }
    
    

    I didn't compile this code, but it should as long as you include iostream. Also, this example was very simple and didn't even need to be done this way because of how the compiler would've done the casting for you if you just defined a function that took regular integers.

    You could also look into function overloading, where you define the same function with different argument types, and depending on the arguments that are passed in, the compiler will call the right function.

    NOTE: Function overloading only goes by the arguments, so you cannot overload just by the return type.
  2. In Topic: Writing to text file.

    Posted 26 Apr 2013

    Like I said, you still haven't posted a complete program. No where is answers_text defined. Until I can see a full program, I can't mind read or make guesses.
  3. In Topic: Writing to text file.

    Posted 26 Apr 2013

    One problem I see is in this function:
    void Question::createandwritefile()
    {
        int x;
        file.open("/Users/leanne_rutledge/Desktop/MultiplyChoiceQuestions.txt", ios_base::app);
     
        file << question_text << "\n";
        for(x = 0; x <= 4; x++)
          file << answers_text[x] << "\n\n\n";
    
        file.close();
    }
    
    

    If answers_text is only an array of four elements, then you're looping one extra time.
  4. In Topic: Writing to text file.

    Posted 26 Apr 2013

    Where is answers_text declared?
  5. In Topic: Grids+Movement

    Posted 26 Apr 2013

    It may have to do with conio.h.

My Information

Member Title:
D.I.C Lover
Age:
Age Unknown
Birthday:
Birthday Unknown
Gender:

Contact Information

E-mail:
Click here to e-mail me

Friends

vividexstance hasn't added any friends yet.

Comments

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