Thread: Classes and redefinition; different basic types help

  1. #1
    Registered User
    Join Date
    Sep 2009
    Posts
    16

    Question Classes and redefinition; different basic types help

    Hey all i am trying to compile my code but i keep getting "redefinition; different basic types". Here is the error log:
    f:\c++2\addressClass\addressClass.cpp(145): error C2556: 'std::string extPersonType::getNumber(void) const' : overloaded function differs only by return type from 'int extPersonType::getNumber(void) const'
    f:\c++2\addressClass\addressClass.cpp(35) : see declaration of 'extPersonType::getNumber'
    f:\c++2\addressClass\addressClass.cpp(97): error C2371: 'addressType::getZip' : redefinition; different basic types
    f:\c++2\addressClass\addressClass.cpp(16) : see declaration of 'addressType::getZip'
    f:\c++2\addressClass\addressClass.cpp(145): error C2371: 'extPersonType::getNumber' : redefinition; different basic types
    f:\c++2\addressClass\addressClass.cpp(35) : see declaration of 'extPersonType::getNumber'
    f:\c++2\addressClass\addressClass.cpp(97): error C2556: 'std::string addressType::getZip(void) const' : overloaded function differs only by return type from 'int addressType::getZip(void) const'
    And here is my code that its having problems with:
    Code:
    #include <string>
    #include <assert.h>
    #include <iostream>
    #include <windows.h>
    
    using namespace std;
    
    class addressType
    {
    public:
    	void printAddress() const;
    	void setAddress(string street, string city, string state, int zip);
    	string getStreet() const;
    	string getCity() const;
    	string getState() const;
    	int getZip() const;
    	addressType(string street = "", string city = "", string state = "", int zip = 0);
    	
    private:
    	string addrStreet;
    	string addrCity;
    	string addrState;
    	int addrZip;
    };
    
    class extPersonType
    {
    public:
    	void printPerson() const;
    	void setNameNum(string first, string last, int number);
    	void setPersonType(string pt);
    	string getFirstName() const;
    	string getLastName() const;
    	string getPersonType() const;
    	int getNumber() const;
    	extPersonType(string first = "", string last = "", int number = 0000000000);
    	
    private:
    	string firstName;
    	string lastName;
    	string personType;
    	int phoneNumber;
    };
    
    string addressType::getZip() const
    {
    	return addrZip;
    }
    
    string extPersonType::getNumber() const
    {
    	return phoneNumber;
    }
    I do not really know what i am doing wrong? Any help would be great!

    David
    Last edited by StealthRT; 10-04-2009 at 12:05 AM.

  2. #2
    Guest Sebastiani's Avatar
    Join Date
    Aug 2001
    Location
    Waterloo, Texas
    Posts
    5,708
    Well, do you want the functions to return an 'int' or a 'string'? The compiler is basically just saying "pick one and stick to it".

  3. #3
    Registered User
    Join Date
    Sep 2009
    Posts
    16
    Yep, i just noticed i had "string" instead of "int.
    Code:
    string addressType::getZip() const
    {
    	return addrZip;
    }
    
    string extPersonType::getNumber() const
    {
    	return phoneNumber;
    }
    to..
    Code:
    int addressType::getZip() const
    {
    	return addrZip;
    }
    
    int extPersonType::getNumber() const
    {
    	return phoneNumber;
    }
    David

  4. #4
    The larch
    Join Date
    May 2006
    Posts
    3,573
    I don't think zip codes and phone numbers are really numeric: does it make sense to add two phone-numbers?
    I might be wrong.

    Thank you, anon. You sure know how to recognize different types of trees from quite a long way away.
    Quoted more than 1000 times (I hope).

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Classes
    By bobbelPoP in forum C++ Programming
    Replies: 8
    Last Post: 07-16-2008, 08:48 AM
  2. Having a problem with templates and classes
    By bowluswj in forum C++ Programming
    Replies: 4
    Last Post: 06-26-2007, 12:55 PM
  3. Mutual Classes
    By subdene in forum C++ Programming
    Replies: 9
    Last Post: 06-27-2004, 04:34 PM
  4. Redefinition of classes (#include headers)
    By cjschw in forum C++ Programming
    Replies: 3
    Last Post: 09-04-2003, 09:24 PM
  5. Another question on classes
    By hpy_gilmore8 in forum C++ Programming
    Replies: 26
    Last Post: 05-24-2003, 09:11 AM