错误代码C2679

时间:2017-10-21 07:18:47

标签: c++

按照指南,我得到一个c3867错误(二进制'<<':没有找到操作符,它采用'void'类型的右操作数)但我不完全确定为什么或如何我“解决它。

我正在尝试使用Composition通过人员类调用birthday.printDate函数,我昨天确实启动了CPP,所以我为我所犯的错误道歉(类名不开始大写等)

这是我的代码:

的main.cpp

#include <iostream> 
#include "birthday.h"
#include "people.h"
using namespace std;

int main() {

    birthday birthObj(4, 1, 1998);
    people User("User", birthObj);

    User.printInfo();

    system("pause");
}

people.h

#pragma once
#include <string>
#include "birthday.h"
using namespace std;


class people
{

public:
    people(string x, birthday bo);
    void printInfo();

private:
    string name;
    birthday dateOfBirth;

};

people.cpp

#include "people.h"
#include "birthday.h"
#include <iostream>
using namespace std;



people::people(string x, birthday bo)
    :name(x), dateOfBirth(bo)
{
}

void people::printInfo() {
    cout << name << " was born on " << dateOfBirth.printDate() << endl;

}

birthday.h

#pragma once
class birthday
{
public:
    birthday(int d, int m, int y);
    void printDate();
private:
    int day;
    int month;
    int year;
};

birthday.cpp

#include <iostream> 
#include "birthday.h"
using namespace std;


birthday::birthday(int d, int m, int y){
    day = d;
    month = m;
    year = y;

}

void birthday::printDate() {
    cout << day << "/" << month << "/" << year << endl;

}

我尽可能地遵循了给出的建议,但我仍然不明白为什么我不能打电话给printDate。

0 个答案:

没有答案