이게 어째서 l-value가 아닌거죠!! ㅠㅠ

oneclubs의 이미지

ㅠㅠ

왜 이게 l-value가 아닌건가요!!! ㅠㅠ

정말 울고 싶습니다

class Damn{
private :
     Damn *it;
public :
     Damn* WhatIt()
     {
           return it;
     }
};
 
 
func()
{
    Damn shit;
    shit.WhatIt() = Something.. <-- 이부분
}

저부분입니다..
컴파일러 : shit.WhatIt() 이거 lvalue 아니잖아 멍청아

라고 저한테 컴파일러가 시비거는데.. 싸워야되나요 ㅠㅠ
왜..왜 lvalue가 아닌건가요!!
방법은 없나요
컴파일러를 무찌를수 있는 방법좀 전수해주세요 ㅠ

semmal의 이미지

포인터 말고 레퍼런스를 리턴하세요. 컴파일러가 사랑해줄겁니다.
------------------------------
How many legs does a dog have?

------------------------------
How many legs does a dog have?

planetarium의 이미지

함수의 리턴값은 변수 그 자체가 아니라 변수의 값일 뿐입니다.
포인터를 반환한다고 해도, 포인터 자체의 값(주소) 가 반환되는 것이지 어떤 변수가 반환되는 것이 아닙니다.
it 이 5000 번지를 가리키고 있다면 shit.WhatIt() = Something.. 은 5000 = Something.. 과 같은 것이죠.
private 변수의 값을 변경하려면, shit.AnotherIt(Something); 의 형태로 작성하셔야 합니다.

그 기분은 정말 뼛속깊이 이해하지만, 다음부턴 좀 이쁜 단어들을 사용해 주세요 :)

oneclubs의 이미지

Damn* WhatIt() 이거를 레퍼런스로 바꿔서
Damn& WhatIt()

이렇게 쓰면 이러한 에러가 납니다.
Damn * 를 Damn&로 변환할수 없다고 합니다.
..

되야 하는거 아닌가요?

oneclubs의 이미지

끙끙되다..
Damn*& WhatIt()이렇게.. 포인터에 대한 레퍼런스로 바꾸니까 일단 해결은 쭉쭉 되는데

와 이게 무슨소린지..답변 감사합니다.

semmal의 이미지

Damn* WhatIt() { return it; }

*shit.WhatIt() = Something();

또는

Damn& WhatIt() { return *it; }

shit.WhatIt() = Something();

*&를 보니 참 감회가 새롭군요.
------------------------------
How many legs does a dog have?

------------------------------
How many legs does a dog have?

댓글 달기

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