|
-
March 18th, 2007, 07:33 PM
#1
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
-
March 18th, 2007, 07:49 PM
#2
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).
-
March 18th, 2007, 07:57 PM
#3
Re: Why am I getting these errors?
 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
-
March 18th, 2007, 08:03 PM
#4
Re: Why am I getting these errors?
Windows XP, Visual Studio 2008, SVN
-
March 18th, 2007, 08:05 PM
#5
Re: Why am I getting these errors?
 Originally Posted by Calculator
dead link?
-
March 18th, 2007, 08:13 PM
#6
Re: Why am I getting these errors?
 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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|