Проблемы с доступом к переменным класса при использовании файлов заголовков/исходных файлов.C++

Программы на C++. Форум разработчиков
Ответить Пред. темаСлед. тема
Anonymous
 Проблемы с доступом к переменным класса при использовании файлов заголовков/исходных файлов.

Сообщение Anonymous »

Я пытаюсь использовать файлы заголовков и их исходные файлы, но когда я пытаюсь получить доступ к классам внутри них, у меня возникают проблемы. Вот код моего файла заголовка:

Код: Выделить всё

// person.h

namespace PersonFuncs
{
class Person;

void getValues ( Person& );
void setValues ( Person& );
}
И исходный файл моих заголовков:

Код: Выделить всё

// person.cpp
#include 
#include 
#include "person.h"

using namespace std;

namespace PersonFuncs
{
class Person
{
private:
string name; // Declaring string variable to hold person's name
int height; // Declaring integer variable to hold person's height
public:
string getName() const; // Reads from 'name' member variable
void setName ( string ); // Writes to the 'name' member variable
int getHeight() const; // Reads from the 'height' member variable
void setHeight ( int ); // Writes to the 'height' member variable
};

string Person::getName() const
{
return name;
}
void Person::setName ( string s )
{
if ( s.length() == 0 ) // If user does not input the name then assign with statement
name = "No name assigned";
else // Otherwise assign with user input
name = s;
}
int Person::getHeight() const
{
return height;
}
void Person::setHeight ( int h )
{
if ( h < 0 ) // If user does not input anything then assign with 0 (NULL)
height = 0;
else // Otherwise assign with user input
height = h;
}

void getValues ( Person& pers )
{
string str; // Declaring variable to hold person's name
int h; // Declaring variable to hold person's height

cout  h;
cin.ignore();

pers.setHeight ( h ); // Passing person's name to it's holding member
}
void setValues ( Person& pers )
{
cout 

Подробнее здесь: [url]https://stackoverflow.com/questions/8625450/trouble-with-accessing-class-variables-when-using-header-source-files[/url]
Реклама
Ответить Пред. темаСлед. тема

Быстрый ответ

Изменение регистра текста: 
Смайлики
:) :( :oops: :roll: :wink: :muza: :clever: :sorry: :angel: :read: *x)
Ещё смайлики…
   
К этому ответу прикреплено по крайней мере одно вложение.

Если вы не хотите добавлять вложения, оставьте поля пустыми.

Максимально разрешённый размер вложения: 15 МБ.

  • Похожие темы
    Ответы
    Просмотры
    Последнее сообщение

Вернуться в «C++»