Constructor troubles

Please support our C++ advertiser: Intel Parallel Studio Home
Reply

Join Date: Aug 2006
Posts: 10
Reputation: V1RuZ is an unknown quantity at this point 
Solved Threads: 0
V1RuZ V1RuZ is offline Offline
Newbie Poster

Constructor troubles

 
1
  #1
Sep 4th, 2006
Hi out there.

I can't get the constructors in my header files to work.

Here's a copy of my header file code:

  1. #ifndef GUARD_PHEADER_H
  2. #define GUARD_PHEADER_H
  3.  
  4. //The header file for the Person.cpp.
  5. //person_header.h
  6.  
  7. #include <iostream>
  8. #include <string>
  9.  
  10. //Person class declaration
  11. class Person {
  12. public:
  13. std::istream& read_surname(std::istream&);
  14. std::istream& read_name(std::istream&);
  15. std::istream& read_phone(std::istream&);
  16. std::istream& read_age(std::istream&);
  17. std::istream& read_weight(std::istream&);
  18. std::string& read_phone(std::string&);
  19. int& read_age(int&);
  20. double& read_weight(double&);
  21. std::string get_name() const { return name; }
  22. std::string get_surname() const { return surname; }
  23. std::string get_phone() const { return phone; }
  24. int get_age() const { return age; }
  25. double get_weight() const { return weight; }
  26. person(std::string&, std::string&, std::string&, int&, double&);
  27. Person(std::ifstream&);
  28. private:
  29. std::string surname;
  30. std::string name;
  31. std::string phone;
  32. int age;
  33. double weight;
  34. };
  35. #endif
And a copy of the function code:
  1. //Constructor for Person
  2.  
  3. Person::person(std::ifstream& in) : surname(0), name(0), phone(0), age(0), weight(0.0) { }
  4.  
  5. //Constructor for Person
  6. Person::person(): surname(0), name(0), phone(0), age(0), weight(0.0) { }
I keep getting all the weird errors that you can find in my compile log. I'm running Dev C++ on Windows XP.

Thanx:cheesy:
Steven
Reply With Quote Quick reply to this message  
Join Date: Aug 2006
Posts: 10
Reputation: V1RuZ is an unknown quantity at this point 
Solved Threads: 0
V1RuZ V1RuZ is offline Offline
Newbie Poster

Re: Constructor troubles

 
1
  #2
Sep 4th, 2006
Oh Yeah, and here's my compiler log...

Compiler: Default compiler
Building Makefile: "C:\Documents and Settings\Steven\Desktop\CTI\C++ Unit 3\Finished Project\Makefile.win"
Executing make...
make.exe -f "C:\Documents and Settings\Steven\Desktop\CTI\C++ Unit 3\Finished Project\Makefile.win" all
g++.exe -c person.cpp -o person.o -I"C:/Dev-Cpp/lib/gcc/mingw32/3.4.2/include" -I"C:/Dev-Cpp/include/c++/3.4.2/backward" -I"C:/Dev-Cpp/include/c++/3.4.2/mingw32" -I"C:/Dev-Cpp/include/c++/3.4.2" -I"C:/Dev-Cpp/include"

In file included from person.cpp:8:
person_header.h:26: error: ISO C++ forbids declaration of `person' with no type
person.cpp:68: error: ISO C++ forbids declaration of `person' with no type
person.cpp:68: error: prototype for `int Person::person(std::ifstream&)' does not match any in class `Person'
person_header.h:26: error: candidate is: int Person::person(std::string&, std::string&, std::string&, int&, double&)
person.cpp: In member function `int Person::person(std::ifstream&)':
person.cpp:68: error: only constructors take base initializers
person.cpp: At global scope:
person.cpp:71: error: ISO C++ forbids declaration of `person' with no type
person.cpp:71: error: prototype for `int Person::person()' does not match any in class `Person'
person.cpp:68: error: candidates are: int Person::person(std::ifstream&)
person_header.h:26: error: int Person::person(std::string&, std::string&, std::string&, int&, double&)
person.cpp: In member function `int Person::person()':
person.cpp:71: error: only constructors take base initializers

make.exe: *** [person.o] Error 1

Execution terminated
Reply With Quote Quick reply to this message  
Join Date: Aug 2006
Posts: 10
Reputation: V1RuZ is an unknown quantity at this point 
Solved Threads: 0
V1RuZ V1RuZ is offline Offline
Newbie Poster

Re: Constructor troubles

 
1
  #3
Sep 4th, 2006
Oh yeah, the error on line 26 occurs in the header and 68 and 71 occur in the definition of the functions
Reply With Quote Quick reply to this message  
Join Date: Apr 2004
Posts: 4,359
Reputation: Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future 
Solved Threads: 239
Team Colleague
Dave Sinkula's Avatar
Dave Sinkula Dave Sinkula is offline Offline
long time no c

Re: Constructor troubles

 
1
  #4
Sep 4th, 2006
Remeber that C++ is case-sensitive (uppercase and lowercase matter).
Last edited by Dave Sinkula; Sep 4th, 2006 at 11:02 pm.
"One of the methods used by statists to destroy capitalism consists in establishing controls that tie a given industry hand and foot, making it unable to solve its problems, then declaring that freedom has failed and stronger controls are necessary." --Ayn Rand
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC