const 포인터 반환

vani2의 이미지

const 포인터를 반환하는 함수는 어떻게 만드나요?

클래스 멤버에서 사용할려하는데요..

const함수 만으로 보호가 될까요?

klara의 이미지

반환형에 const를 붙이면 되죠.

vani2의 이미지

아.

그것이 가능한 문법인가요?

익명 사용자의 이미지

const는 reference와 function을 제외한 모든 타입에 붙일 수 있습니다.

(혹시나해서 첨언하자면 const T& 는 (const T)& 이지 const (T&)가 아닙니다.)

연습으로 const T 타입에 대한 const pointer의 타입을 표현해보세요.

vani2의 이미지

그렇다면 reference타입에 붙는 const는 의미가 없는건가요?

member function에는 const가 사용될 수 있는데 function에 사용되는 방법은 이 경우 하나뿐인가요?

const T* const N 이것이 const 타입T를 표현하는 const 포인터가 맞을까요?

익명 사용자의 이미지

> 그렇다면 reference타입에 붙는 const는 의미가 없는건가요?

이미 말씀드렸듯이 const T& 는 (const T)& 이지 const (T&)가 아닙니다.
reference는 "원래" const입니다. 값이 바뀔 수 없지요.

> member function에는 const가 사용될 수 있는데 function에 사용되는 방법은 이 경우 하나뿐인가요?

function 타입에 const가 사용될 수 없는 것은 reference와 같은 이유에서 입니다.
원래 const입니다. foo라는 이름의 함수를 만들고 나중에 foo가 다른 함수에 대한 이름이 되도록 바꿀 수 없습니다.

[member function에 대한 const]는 [타입에 대한 cv-qualifier로서의 const]와 의미가 다릅니다.
밀접하게 연관되어 있지만, 어쨌거나 같은 것은 아닙니다.

> const T* const N 이것이 const 타입T를 표현하는 const 포인터가 맞을까요?

네 맞습니다. 두 const가 각각 어떤 의미인지 알고계시면 제대로 알고계신겁니다.

익명 사용자의 이미지

혹시 헛갈리실까봐 첨언하면 (const T)&나 const (T&)는 의미상 그렇다는 것이지
실제로 이 문법으로 쓸 수는 없습니다.

vani2의 이미지

네.

친절한 설명 감사드립니다.

잘 이해가 되었습니다.

댓글 달기

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
이것은 자동으로 스팸을 올리는 것을 막기 위해서 제공됩니다.