Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. reference question

reference question

Scheduled Pinned Locked Moved C / C++ / MFC
questioncomhelp
3 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • F Offline
    F Offline
    focusdoit
    wrote on last edited by
    #1

    I found, a statement, int &a = 1; the statement can be built in QT Creator, mingw_64. while on Programiz: Learn to Code for Free[^] Got,

    gcc /tmp/BlXEG8NqhU.c -lm
    /tmp/BlXEG8NqhU.c: In function 'main':
    /tmp/BlXEG8NqhU.c:6:15: error: expected identifier or '(' before '&' token
    6 | const int &a = 2;

    so the int &a = 1; is that right? a is a bias name of "1" in rodata?

    K L 2 Replies Last reply
    0
    • F focusdoit

      I found, a statement, int &a = 1; the statement can be built in QT Creator, mingw_64. while on Programiz: Learn to Code for Free[^] Got,

      gcc /tmp/BlXEG8NqhU.c -lm
      /tmp/BlXEG8NqhU.c: In function 'main':
      /tmp/BlXEG8NqhU.c:6:15: error: expected identifier or '(' before '&' token
      6 | const int &a = 2;

      so the int &a = 1; is that right? a is a bias name of "1" in rodata?

      K Offline
      K Offline
      k5054
      wrote on last edited by
      #2

      I suspect that whatever QT Creator is doing is somehow creating a const reference . e.g.

      int &a = 1; // fails to compile
      const int &b = 2; // compiles fine

      Consider what int &a = 1 means: I.E. create a reference to the integer 1. If that were to compile successfully then consider

      int &a = 1;
      a = 2;
      std::cout << 1 + 1 << '\n';

      By the rules of C++, at least as I understand them, that should print 4, since you've changed the value of 1 to 2 at the assignment statement.

      Keep Calm and Carry On

      1 Reply Last reply
      0
      • F focusdoit

        I found, a statement, int &a = 1; the statement can be built in QT Creator, mingw_64. while on Programiz: Learn to Code for Free[^] Got,

        gcc /tmp/BlXEG8NqhU.c -lm
        /tmp/BlXEG8NqhU.c: In function 'main':
        /tmp/BlXEG8NqhU.c:6:15: error: expected identifier or '(' before '&' token
        6 | const int &a = 2;

        so the int &a = 1; is that right? a is a bias name of "1" in rodata?

        L Offline
        L Offline
        Lost User
        wrote on last edited by
        #3

        You are trying to use a C++ construct in a C-language program.

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups