c++질문입니다

gayeon298의 이미지

class Scanner
{
private:
	ifstream fin; // 입력스트림 
	ofstream fout; // 출력스트림
 
public:
	Scanner(char *a,char *b); // 생성자
	~Scanner(); // 소멸자
	void lexicalError(int n); // 어휘 분석시 에러 메세지 출력
	int superLetter(char ch); // 입력받은 문자가 letter이거나 _인지 검사하는 함수
	int superLetterOrDigit(char ch); //	입력받은 문자가 letter, number, _인지 검사하는 함수	
	int	hexValue(char ch); // 16진수를 10진수로 변환하는 함수	
	int getIntNum(char firstCharacter); // 정수상수를 처리하는 함수
	struct tokenType scanner(); // 입력프로그램에서 한 개의 토큰을 분할해서 복귀하는 함수
ofstream Fout(){ // 출력스트림함수
		return fout;
	}
};

삭제된 함수라고 나오는데 왜 그러는 걸까요?

세벌의 이미지

익명 사용자의 이미지

1. 주어진 클래스는 소멸자를 직접 정의했습니다.
그 결과 이동 생성자 및 이동 대입 연산자가 자동으로 작성되지 않습니다.

2. 주어진 클래스는 ifstream 및 ofstream 객체를 포함하고 있습니다.
그 객체들은 복사가 되지 않습니다. 결국 주어진 클래스 역시 복사가 안 됩니다.

3. 분명 코드 어디선가 Scanner 객체를 이동 혹은 복사하려고 했을 겁니다.
위에 썼듯이 둘 다 불가능하므로 에러가 납니다.

======

ifstream 및 ofstream 객체가 복사 불가능한 건 이유가 있습니다.
귀하의 클래스가 ifstream 및 ofstream 객체를 소유해야만 한다면, 귀하의 클래스 역시 복사해서는 안 될 이유가 있는 겁니다.

"이동" 까지는 가능하게 할 수 있습니다. 예컨대,

Scanner(Scanner &&) = default;
Scanner &operator=(Scanner &&) = default;

위와 같이 이동 생성자 및 이동 대입 연산자를 넣어 주면 됩니다. 커스텀 구현을 하셔도 됩니다.

정 복사를 하고 싶으시다면... Scanner를 복사한다는 게 어떤 동작을 의미하는 것인지 진지하게 고민한 후, 그 결과에 따라 적절히 설계를 다시 해 주어야 될 겁니다.

======

Modern C++는 여러 모로 편리한 기능들이 추가되긴 했지만, "모르면 처 맞아야지" 싶은 기능들이 여기저기 늘어서, 더욱 초보자에게 비친화적인 언어가 되지 않았나 싶습니다.

왜 이 언어로 개발을 하고 계신 건지는 모르겠으나... 화이팅.

댓글 달기

Filtered HTML

  • 텍스트에 BBCode 태그를 사용할 수 있습니다. URL은 자동으로 링크 됩니다.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>
  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.

BBCode

  • 텍스트에 BBCode 태그를 사용할 수 있습니다. URL은 자동으로 링크 됩니다.
  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param>
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.

Textile

  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • You can use Textile markup to format text.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>

Markdown

  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • Quick Tips:
    • Two or more spaces at a line's end = Line break
    • Double returns = Paragraph
    • *Single asterisks* or _single underscores_ = Emphasis
    • **Double** or __double__ = Strong
    • This is [a link](http://the.link.example.com "The optional title text")
    For complete details on the Markdown syntax, see the Markdown documentation and Markdown Extra documentation for tables, footnotes, and more.
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>

Plain text

  • HTML 태그를 사용할 수 없습니다.
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.
  • 줄과 단락은 자동으로 분리됩니다.
댓글 첨부 파일
이 댓글에 이미지나 파일을 업로드 합니다.
파일 크기는 8 MB보다 작아야 합니다.
허용할 파일 형식: txt pdf doc xls gif jpg jpeg mp3 png rar zip.
CAPTCHA
이것은 자동으로 스팸을 올리는 것을 막기 위해서 제공됩니다.