Hi out there.

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

Here's a copy of my header file code:

#ifndef GUARD_PHEADER_H
#define GUARD_PHEADER_H

//The header file for the Person.cpp.
//person_header.h

#include <iostream>
#include <string>

//Person class declaration
class Person {
public:
       std::istream& read_surname(std::istream&);
       std::istream& read_name(std::istream&);
       std::istream& read_phone(std::istream&);
       std::istream& read_age(std::istream&);
       std::istream& read_weight(std::istream&);
       std::string& read_phone(std::string&);
       int& read_age(int&);
       double& read_weight(double&);
       std::string get_name() const { return name; }
       std::string get_surname() const { return surname; }
       std::string get_phone() const { return phone; }
       int get_age() const { return age; }
       double get_weight() const { return weight; }
       person(std::string&, std::string&, std::string&, int&, double&);
       Person(std::ifstream&);
private:
        std::string surname;
        std::string name;
        std::string phone;
        int age;
        double weight;
    };    
#endif

And a copy of the function code:

//Constructor for Person

Person::person(std::ifstream& in) : surname(0), name(0), phone(0), age(0), weight(0.0) { }

//Constructor for Person
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

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

Oh yeah, the error on line 26 occurs in the header and 68 and 71 occur in the definition of the functions

Remeber that C++ is case-sensitive (uppercase and lowercase matter).

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.