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
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).
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
Re: Why am I getting these errors?
Re: Why am I getting these errors?
Quote:
Originally Posted by Calculator
dead link?
Re: Why am I getting these errors?
Quote:
Originally Posted by Mr. Mojo Risin
dead link?
finally connected. I'll note the advice.
thanks