Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. [SOLVED] variable scope
Forum Updated to NodeBB v4.3 + New Features

[SOLVED] variable scope

Scheduled Pinned Locked Moved General and Desktop
4 Posts 2 Posters 985 Views 2 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.
  • H Offline
    H Offline
    harry
    wrote on last edited by harry
    #1

    hi

    in my button.h file i have this:

    private:
        int size;
    

    and in my button.cpp file i have this code:

    int getSize() {
        return size;
    }
    

    the problem that drives me nuts is that when i try to build, i get an error " 'size' was not declared in this scope" on the 'return size;' line. what am i doing wrong? i declare the variable in the header, so why is it 'not declared in this scope'?

    1 Reply Last reply
    0
    • mrjjM Offline
      mrjjM Offline
      mrjj
      Lifetime Qt Champion
      wrote on last edited by mrjj
      #2

      Hi
      is that a member of a class?
      int size; I mean

      then syntax is:

      int SomeClass::getSize() {
      return size;
      }

      else it just a normal function and it doesn't know any size to return as its not defined in the function or as global.

      Note: SomeClass is the class that "int size" is defined in.

      H 1 Reply Last reply
      0
      • mrjjM mrjj

        Hi
        is that a member of a class?
        int size; I mean

        then syntax is:

        int SomeClass::getSize() {
        return size;
        }

        else it just a normal function and it doesn't know any size to return as its not defined in the function or as global.

        Note: SomeClass is the class that "int size" is defined in.

        H Offline
        H Offline
        harry
        wrote on last edited by
        #3

        @mrjj said:

        Hi
        is that a member of a class?
        int size; I mean

        then syntax is:

        int SomeClass::getSize() {
        return size;

        i added the class name and now it works. thanx.

        mrjjM 1 Reply Last reply
        0
        • H harry

          @mrjj said:

          Hi
          is that a member of a class?
          int size; I mean

          then syntax is:

          int SomeClass::getSize() {
          return size;

          i added the class name and now it works. thanx.

          mrjjM Offline
          mrjjM Offline
          mrjj
          Lifetime Qt Champion
          wrote on last edited by
          #4

          @harry
          super. please mark it SOLVED if possible :)

          1 Reply Last reply
          0

          • Login

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved