Errors I don't understand (overloading)

This is a discussion on Errors I don't understand (overloading) within the C++ Programming forums, part of the General Programming Boards category; I get: Code: Warning W8066 d.cpp 11: Unreachable code in function main() Warning W8004 d.cpp 10: 'exp' is assigned a ...

  1. #1
    fuh
    fuh is offline
    Attack hamster fuh's Avatar
    Join Date
    Dec 2002
    Posts
    176

    Errors I don't understand (overloading)

    I get:
    Code:
    Warning W8066 d.cpp 11: Unreachable code in function main()
    Warning W8004 d.cpp 10: 'exp' is assigned a value that is never used in function
     main()
    Error E2335 d.cpp 15: Overloaded 'exp' ambiguous in this context in function levup()
    Error E2335 d.cpp 16: Overloaded 'exp' ambiguous in this context in function levup()
    for:
    Code:
    #include <iostream.h>
    #include <conio.h>
    #include <stdlib.h>
    #include <string>
    void levup();
    int level=1;
    int main()
    {
    int exp=99;
    for(;;){ exp++;cout<<"Your level is: "<<level; levup();}
    getch();
    return 0;
    }
    void levup(){
    if (exp==100){
    exp=0;
    level++;
    }
    return;
    }
    Could someone tell me what I'm doing wrong?
    P.S.:This is a part of my new RPG.
    Stupid things pop singers say

    "I get to go to lots of overseas places, like Canada."
    - Britney Spears

    "I love what you've done with the place!"
    -Jessica Simpson upon meeting the Secretary of Interior during tour of the White House

  2. #2
    Registered User
    Join Date
    Nov 2002
    Posts
    491
    Your for loop goes on for ever, there is no way to get out of it.

    In levup(), where does this exp variable come into scope? It is not global and it is not defined in the function.

    Why does your void function have a return; in it?

  3. #3
    fuh
    fuh is offline
    Attack hamster fuh's Avatar
    Join Date
    Dec 2002
    Posts
    176
    I still get errors for:
    Code:
    #include <iostream.h>
    #include <conio.h>
    #include <stdlib.h>
    #include <string>
    void levup();
    int exp=0;
    int level=1;
    int main()
    {
    while(level<100){ 
    exp++;
    cout<<"Your level is: "<<level; 
    levup();
    getch();
    }
    return 0;
    }
    void levup(){
    if (exp==100){
    exp=0;
    level++;
    }
    }
    And the errors:
    Code:
    Error E2356 d.cpp 6: Type mismatch in redeclaration of 'exp(double)'
    Error E2063 d.cpp 6: Illegal initialization
    Error E2141 d.cpp 6: Declaration syntax error
    Error E2335 d.cpp 11: Overloaded 'exp' ambiguous in this context in function mai
    n()
    Error E2335 d.cpp 19: Overloaded 'exp' ambiguous in this context in function lev
    up()
    Error E2335 d.cpp 20: Overloaded 'exp' ambiguous in this context in function lev
    up()
    Last edited by fuh; 01-03-2003 at 07:19 PM.
    Stupid things pop singers say

    "I get to go to lots of overseas places, like Canada."
    - Britney Spears

    "I love what you've done with the place!"
    -Jessica Simpson upon meeting the Secretary of Interior during tour of the White House

  4. #4
    _ Munkey01's Avatar
    Join Date
    Dec 2002
    Posts
    280
    I am in a hurry but-

    Code:
    int exp;
    exp=0;
    shoudl be
    Code:
    int exp=0;

  5. #5
    Registered User
    Join Date
    Nov 2002
    Posts
    1,109
    try this:
    Code:
    #include <iostream>
    #include <conio.h>
    #include <cstdlib>
    #include <cstring>
    using namespace std;
    
    void levup(int &exp, int &level);
    
    int main()
    {
    	int exp = 0, level = 1;
    	
    	while(level<100){
    		exp++;
    		cout<<"Your level is: "<<level;
    		levup(exp, level);
    		getch();
    	}
    	
    	return 0;
    }
    void levup(int &exp, int &level){
    	if (exp==100){
    		exp=0;
    		level++;
    	}
    }
    try to avoid using global variables also. this compiles, should do what you want it to.

  6. #6
    End Of Line Hammer's Avatar
    Join Date
    Apr 2002
    Posts
    6,231
    >>Type mismatch in redeclaration ...
    Your name is clashing with another.
    When all else fails, read the instructions.
    If you're posting code, use code tags: [code] /* insert code here */ [/code]

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. global namespace errors
    By stubaan in forum C++ Programming
    Replies: 9
    Last Post: 04-02-2008, 04:11 PM
  2. Ten Errors
    By AverageSoftware in forum Contests Board
    Replies: 0
    Last Post: 07-20-2007, 11:50 AM
  3. Unknown Errors in simple program
    By neandrake in forum C++ Programming
    Replies: 16
    Last Post: 04-06-2004, 03:57 PM
  4. Stupid compiler errors
    By ChrisEacrett in forum C++ Programming
    Replies: 9
    Last Post: 11-30-2003, 05:44 PM
  5. errors in class(urgent)
    By ayesha in forum C++ Programming
    Replies: 2
    Last Post: 11-10-2001, 06:51 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21