Ошибка 1 error C2758: "Person::_address": требуется инициализация члена ссылочного типа c:\users\dmb\documents\visual studio 2013\projects\pointers\pointers\person.cpp 4 1 Pointers
2 IntelliSense: "Person::Person(std::string name, Address &address)" не предоставляет инициализатор для:
ссылка член "Person::_address" c:\Users\dmb\Documents\Visual Studio 2013\Projects\Pointers\Pointers\Person.cpp 4 1 Pointers
Program.cpp#include <iostream>
#include "Person.h"
using namespace std;
void DisplayPersonInfo(Person& person);
int main()
{
setlocale(LC_ALL, "Rus");
Address* address = new Address("Пушкина", 8);
Person* person = new Person("Алексей", *address);
DisplayPersonInfo(*person);
delete address;
delete person;
system("pause");
return EXIT_SUCCESS;
}
void DisplayPersonInfo(Person& person)
{
cout << "Имя: " << person.name() << "\n" << endl;
cout << "Адрес: " << person.address().street() << "\n" << endl;
}
Address.h#pragma once
#include <string>
using namespace std;
class Address
{
string _street;
unsigned short int _houseNumber;
public:
Address(string street, unsigned short int houseNumber);
~Address();
string street()
{
return _street;
}
unsigned short int houseNumber()
{
return _houseNumber;
}
};
Address.cpp#include "Address.h"
Address::Address(string street, unsigned short int houseNumber)
{
_street = street;
_houseNumber = houseNumber;
}
Address::~Address()
{
}
Person.h#pragma once
#include <string>
#include "Address.h"
using namespace std;
class Person
{
string _name;
Address& _address;
public:
Person(string name, Address& address);
~Person();
void setName(string& name)
{
_name = name;
}
string& name()
{
return _name;
}
Address& address()
{
return _address;
}
};
Person.cpp#include "Person.h"
Person::Person(string name, Address& address)
{
_name = name;
_address = address;
}
Person::~Person()
{
}