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. "const" statement causes errors

"const" statement causes errors

Scheduled Pinned Locked Moved C / C++ / MFC
visual-studiohelp
8 Posts 6 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.
  • V Offline
    V Offline
    Vladimir Dubovoy
    wrote on last edited by
    #1

    Hi! I just try to implement class with members which return const values: class MyClass{ * * * protected: float GetVal() const {return val;} private: float val; } It compiled well without "const" but with it I got multiple errors. I can not avoid of use "const" becuse I must follow some coding style. So your help is very essential for me. I code in VS 6.

    M 2 A M Y 5 Replies Last reply
    0
    • V Vladimir Dubovoy

      Hi! I just try to implement class with members which return const values: class MyClass{ * * * protected: float GetVal() const {return val;} private: float val; } It compiled well without "const" but with it I got multiple errors. I can not avoid of use "const" becuse I must follow some coding style. So your help is very essential for me. I code in VS 6.

      M Offline
      M Offline
      Mad__
      wrote on last edited by
      #2

      You function return value ;) why const ? ;)

      1 Reply Last reply
      0
      • V Vladimir Dubovoy

        Hi! I just try to implement class with members which return const values: class MyClass{ * * * protected: float GetVal() const {return val;} private: float val; } It compiled well without "const" but with it I got multiple errors. I can not avoid of use "const" becuse I must follow some coding style. So your help is very essential for me. I code in VS 6.

        2 Offline
        2 Offline
        224917
        wrote on last edited by
        #3

        The code you posted compiles fine on vc6. Did you missed something ?
        There is no spoon. mail

        1 Reply Last reply
        0
        • V Vladimir Dubovoy

          Hi! I just try to implement class with members which return const values: class MyClass{ * * * protected: float GetVal() const {return val;} private: float val; } It compiled well without "const" but with it I got multiple errors. I can not avoid of use "const" becuse I must follow some coding style. So your help is very essential for me. I code in VS 6.

          A Offline
          A Offline
          Antony M Kancidrowski
          wrote on last edited by
          #4

          What errors did you get? Ant. I'm hard, yet soft.
          I'm coloured, yet clear.
          I'm fruity and sweet.
          I'm jelly, what am I? Muse on it further, I shall return!
          - David Williams (Little Britain)

          V 1 Reply Last reply
          0
          • A Antony M Kancidrowski

            What errors did you get? Ant. I'm hard, yet soft.
            I'm coloured, yet clear.
            I'm fruity and sweet.
            I'm jelly, what am I? Muse on it further, I shall return!
            - David Williams (Little Britain)

            V Offline
            V Offline
            Vladimir Dubovoy
            wrote on last edited by
            #5

            Thanks to all. I just fix it. The metter was not in "const" but in member name.

            1 Reply Last reply
            0
            • V Vladimir Dubovoy

              Hi! I just try to implement class with members which return const values: class MyClass{ * * * protected: float GetVal() const {return val;} private: float val; } It compiled well without "const" but with it I got multiple errors. I can not avoid of use "const" becuse I must follow some coding style. So your help is very essential for me. I code in VS 6.

              M Offline
              M Offline
              Malcolm Smart
              wrote on last edited by
              #6

              Like Mad___ said, you are returning a value - why would you want to return a const value? Isn't it the member, val, that is const? The method doesn't know the type of variable the return value is being stored in? Can anybody help please?!!? Cheers Angel =========================================================== The sooner you fall behind, the longer you have to catch up

              V 1 Reply Last reply
              0
              • M Malcolm Smart

                Like Mad___ said, you are returning a value - why would you want to return a const value? Isn't it the member, val, that is const? The method doesn't know the type of variable the return value is being stored in? Can anybody help please?!!? Cheers Angel =========================================================== The sooner you fall behind, the longer you have to catch up

                V Offline
                V Offline
                Vladimir Dubovoy
                wrote on last edited by
                #7

                As I said I MUST code in certain style. So 'const' comes out of it.:):):)

                1 Reply Last reply
                0
                • V Vladimir Dubovoy

                  Hi! I just try to implement class with members which return const values: class MyClass{ * * * protected: float GetVal() const {return val;} private: float val; } It compiled well without "const" but with it I got multiple errors. I can not avoid of use "const" becuse I must follow some coding style. So your help is very essential for me. I code in VS 6.

                  Y Offline
                  Y Offline
                  yang763876248
                  wrote on last edited by
                  #8

                  You must add const in return type. Like this: const float GetVal()const {return val;} Because the type of val had been upgraded into "const float" in the GetVal function.

                  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