CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 6 of 6
  1. #1
    Join Date
    Feb 2006
    Posts
    132

    Why am I getting these errors?

    I haven't programmed in C++ for awhile and I'm trying to work on an assignment for a C++ Data Structures class, so please excuse my question. I am rusty.

    Anyway I am getting a bunch of errors like:

    error C2146: syntax error : missing ')' before identifier 'theStreet'

    addresstype.h(9) : error C2146: syntax error : missing ';' before identifier 'theStreet'

    error C2460: 'addressType::string' : uses 'addressType', which is being defined

    and more

    addressType.h
    Code:
    #include <string>
    
    class addressType
    {
    public:
    
    	addressType(string theStreet, string theCity, string theState, string theZipCode);
    	addressType();
    
    private:
    	string streetAddress;
    	string city;
    	string state;
    	string zipCode;
    };
    addressTypeImp.cpp

    Code:
    #include <iostream>
    #include <string>
    #include "addressType.h"
    
    using namespace std;
    
    addressType::addressType(string theStreet, string theCity, string theState, string theZipCode)
    {
    	streetAddress = theStreet;
    	city = theCity;
    	state = theState;
    	zipCode = theZipCode;
    }
    
    addressType::addressType()  //default constructor
    {
    	streetAddress = "";
    	city = "";
    	state = "";
    	zipCode = "";
    }
    thanks

  2. #2
    Join Date
    Aug 2000
    Location
    West Virginia
    Posts
    7,725

    Re: Why am I getting these errors?

    In the header file, you need to tell the compiler that string is
    in namespace std

    Code:
     class addressType
    {
    public:
    
    	addressType(std::string theStreet, std::string theCity, 
                                         std::string theState, std::string theZipCode);
    	addressType();
    
    private:
    	std::string streetAddress;
    	std::string city;
    	std::string state;
    	std::string zipCode;
    };
    (also, you should pass by const reference instead of by value in
    the constructor).

  3. #3
    Join Date
    Feb 2006
    Posts
    132

    Re: Why am I getting these errors?

    Quote Originally Posted by Philip Nicoletti
    In the header file, you need to tell the compiler that string is
    in namespace std

    Code:
     class addressType
    {
    public:
    
    	addressType(std::string theStreet, std::string theCity, 
                                         std::string theState, std::string theZipCode);
    	addressType();
    
    private:
    	std::string streetAddress;
    	std::string city;
    	std::string state;
    	std::string zipCode;
    };
    (also, you should pass by const reference instead of by value in
    the constructor).
    thanks, but I found what the problem was. I had this problem before in the past

    #include <iostream>
    #include <string>
    using namespace std;
    #include "addressType.h"

    I had to put "using namespace std;" before the header include.

    this fixed things

    thanks

  4. #4
    Join Date
    Aug 2005
    Posts
    478

    Re: Why am I getting these errors?

    In the end it's really your choice but read this

    http://www.parashift.com/c++-faq-lit....html#faq-27.5
    Windows XP, Visual Studio 2008, SVN

  5. #5
    Join Date
    Feb 2006
    Posts
    132

    Re: Why am I getting these errors?

    Quote Originally Posted by Calculator
    In the end it's really your choice but read this

    http://www.parashift.com/c++-faq-lit....html#faq-27.5
    dead link?

  6. #6
    Join Date
    Feb 2006
    Posts
    132

    Re: Why am I getting these errors?

    Quote Originally Posted by Mr. Mojo Risin
    dead link?
    finally connected. I'll note the advice.

    thanks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured