班级构成混乱

时间:2016-05-21 15:08:10

标签: c++

我正在使用代码块v16 *

我收到了这个错误,我无法弄清楚似乎是什么问题:

  

Person.cpp:17:62:注意:不匹配的类型'const std :: basic_string< _CharT,_Traits,_Alloc>'和'void'        std :: cout<< “出生日期:”<< BirthdateObj.showBirthDate();                                                                 ^   处理终止,状态为1(0分钟,0秒(秒))   1个错误,0个警告(0分钟,0秒(s))

这是我的简单程序:

Person.h

#include "Birthdate.h"
#include <iostream>

Birthdate::Birthdate(int day, int month, int year) : day(day), month(month), year(year)
{
    //ctor
}

Birthdate::~Birthdate()
{
    //dtor
}

void Birthdate::showBirthDate()
{
    std::cout << day << "/" << month << "/" << year;
}

Person.cpp

#include <iostream>
#include "Birthdate.h"
#include "Person.h"

int main()
{

    Birthdate BirthdateObj(7, 16, 1995);
    //Birthdate *pBirthdateObj = &BirthdateObj;

    Person PersonObj(20, BirthdateObj);
    Person *pPersonObj = &PersonObj;

    pPersonObj->showPersonInformation();
    //pBirthdateObj->showBirthDate();

    return 0;
}

Birthdate.h

<ListView Name="menuListView" HorizontalAlignment="Center" 
              Grid.Row="1" SelectionChanged="ListView_SelectionChanged" 
              BorderThickness="0,0,0,5" SelectedIndex="0"
              Grid.ColumnSpan="2">

        <ListView.ItemsPanel>
            <ItemsPanelTemplate>
            <StackPanel Orientation="Horizontal"></StackPanel>
        </ItemsPanelTemplate>
         </ListView.ItemsPanel>
        <TextBlock Name="dayTB"  Text="Day" Margin="25 0 0 0" FontSize="18" />
        <TextBlock Name="weekTB" Text="Week" Margin="25 0 0 0" FontSize="18" />
        <TextBlock Name="monthTB" Text="Month" Margin="25 0 0 0" FontSize="18" />

    </ListView>

Birthdate.cpp

def set_latlon(lat, lng)

  factory = RGeo::Geographic.spherical_factory(srid: 4326)

  # NOTE: this method takes the LNG parameter first!
  self.latlon = factory.point(lng, lat)

end

的main.cpp

:point

1 个答案:

答案 0 :(得分:0)

您的生日功能会返回void而不是string。由于cout无法将void输出到标准输出,因此这就是您的错误所在。改变这一行:

std::cout << "Birthdate: " << BirthdateObj.showBirthDate();

为:

std::cout << "Birthdate: ";
BirthdateObj.showBirthDate();

或者,您可以将showBirthdate的返回类型更改为string,并按原样保留上述行。