Я пытаюсь использовать файлы заголовков и их исходные файлы, но когда я пытаюсь получить доступ к классам внутри них, у меня возникают проблемы. Вот код моего файла заголовка:
// 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]
Я пытаюсь использовать файлы заголовков и их исходные файлы, но когда я пытаюсь получить доступ к классам внутри них, у меня возникают проблемы. Вот код моего файла заголовка:
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
У меня есть следующая задача: я включил предварительные заголовки для моего проекта Cmake с использованием target_precompile_headers ($ {application_name} private include/precompilled/pch.h) . Это сработало, однако только для недавно...
У меня есть следующая задача: я включил предварительные заголовки для моего проекта Cmake с использованием target_precompile_headers ($ {application_name} private include/precompilled/pch.h) . Это сработало, однако только для недавно...
У меня есть такая модель:
public partial class ClassTime
{
public int Id { get; set; }
public int ScheduleId { get; set; }
public System.TimeSpan StartClassTime { get; set; }
public System.TimeSpan FinishClassTime { get; set; }
public string...
В настоящее время у меня есть 3 проекта: интерфейс React, серверная часть Springboot и приложение Android APK.
Я хочу знать, как структурировать файлы DockerFile, .env и docker-compose для каждого из них. Когда я Dockerize всю систему (сделаю IMG),...
Я работаю над приложением Laravel, и мне нужна помощь с фильтрацией заголовков на основе их связи с практиками, викторинами и конкурсами. В частности, я хочу получить названия, которые связаны с практиками, но не имеют связанных с ними викторин или...