-4

I am trying to use constructor initializer for name and time but the visual studio is giving me errors, I do not see any issues with it, it seems fine to me, I tried to see the problem, I tried other things as well, Please Help. Thanks you in advance.

Any help really appreciated, I added all the header file and implementation of Entry class, I know it seems, I added so you can see it.

// Entry.h
#pragma once
#include <iostream>
#include <string>
#include "RelationType.h"

using namespace std;

class Name 
{
    public:
    Name();

    Name(string firstName, string middleName, string lastName);

    string GetFristName() const;

    string GetLastName() const;

    string GetMiddleName() const;

    char GetMiddleInitial() const;

    RelationType ComparedTo(Name otherName) const;

    private:
    string first;
    string last;
    string middle;
};

//Entry.cpp
#include "Entry.h"
#include<iostream>
#include <string>

using namespace std;

Entry::Entry() {}

Entry::Entry(string firstName, string middleName, string lastName,
        int initHours, int initMinutes, int initSeconds)  
        : name{ (firstName, middleName, lastName) ,      //name is where its mad at
          time(initHours, initMinutes, initSeconds) } {}

string Entry::GetNameStr () const
{
     return (name.GetFirstName() + ' ' + name.GetLastName());
}

string Entry::GetTimeStr () const
{
     return (name.FirstName() + ' ' + name.LastName());
}


// Name.h
#pragma once
#include <iostream>
#include <string>
#include "RelationType.h"

using namespace std;

class Name
{
    public:
    Name();

    Name(string firstName, string middleName, string lastName);

    string GetFristName() const;

    string GetLastName() const;

    string GetMiddleName() const;

    char GetMiddleInitial() const;

    RelationType ComparedTo(Name otherName) const;

    private:
    string first;
    string last;
    string middle;
};

// RealtionType.h

#pragma once
#ifndef RELATION
#define RELATION

enum RelationType { BEFORE, SAME, AFTER };

#endif

// TimeOfDay.h
#pragma once

class TimeOfDay
{

    public:

    //Intentionally missed const, see what happened without const
    TimeOfDay();                                 // zero timepfday object

    TimeOfDay(int hours, int minutes, int seconds); //takes 3 parameters

    TimeOfDay Increment() const;                //increment by 1 sec

    void Write() const;                         //write the timeofday obj to print

    bool Equal(TimeOfDay otherTime) const;     //true if timeofday obj equals othertime

    bool LessThan(TimeOfDay otherTime) const;  //const, true if the timeofday obj is
                                           //before itherTime
    private:

    int hours;
    int minutes;
    int seconds;
};
Maddy
  • 774
  • 5
  • 14
coding
  • 21
  • 2
  • What do the errors say? – Mitch Jan 21 '18 at 03:00
  • `name{ (firstName, middleName, lastName), time(initHours, initMinutes, initSeconds) }`. This isn't right. – David G Jan 21 '18 at 03:00
  • what is the datatype of name variable – Maddy Jan 21 '18 at 03:09
  • The datatype of Name is Name, from the Entry class Name nmae; Error is "name" is not a nonstatic data member or base class of class – coding Jan 21 '18 at 03:12
  • I do not understand the error, that a issue itself. – coding Jan 21 '18 at 03:14
  • Looks like you pasted in an extra name.h instead of entry.h – user4581301 Jan 21 '18 at 03:15
  • *the visual studio is giving me errors* is a useless problem description. Those errors come with error messages, which are on the screen right in front of you. There is absolutely no excuse for failing to include them in your question so we have that information as well. It's your responsibility to clearly describe the problem, and those error messages are part of the description. They're *on the screen, right in front of you*, but we can't see your screen from here. – Ken White Jan 21 '18 at 03:15
  • The `{` in `... : name { (...` is nonsense. – Aganju Jan 21 '18 at 03:43

1 Answers1

1

Your Entry class constructor code should be something like below

Entry::Entry(string firstName, string middleName, string lastName,
            int initHours, int initMinutes, int initSeconds)  
            : name(firstName, middleName, lastName)
            , time(initHours, initMinutes, initSeconds) {}
Maddy
  • 774
  • 5
  • 14