Results 1 to 3 of 3

Thread: Function not Declared in This Scope error (However I believe I have declared it.....)

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #2
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,328
    Thanks
    317
    Thanked 871 Times in 858 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Function not Declared in This Scope error (However I believe I have declared it..

    "writeReg" is a standalone function. It is not a member of the ADCreader class, therefore it cannot call non-static member functions of the ADCreader class without using an instance of that class. The compiler is telling you that there is no standalone function called "pabort()", which is true. If you want to call the pabort() method of ADCreader, you have to do it through an instance of that class:

    Qt Code:
    1. ADCreader myReader;
    2. myReader.pabort( "Whatever" );
    3.  
    4. // or
    5.  
    6. ADCreader * myReader = new ADCreader;
    7. myReader->pabort( "Whatever" );
    8. delete myReader;
    To copy to clipboard, switch view to plain text mode 

    Probably you don't want to do either of these alternatives, because it is likely you have a global instance of ADCreader that you are using in your program, and that's the one you want to call pabort(). If it isn't visible in the same scope as writeReg(), then you can make it visible by passing it as an argument to writeReg() (preferred) or declaring the global instance as an "extern ADCreader * myGlobalReader;" and ensuring that your global instance is named the same thing and assigned properly.

    I think it would be useful to you to learn to walk in C++ before you run while holding a RaspberryPi. Get a C++ book, learn about classes, scoping, and the like, then have at it.

    --Edit--

    Actually, it looks like you just forgot to make writeReg() a member function of ADCreader, since you have a "readReg" member function already. Still, you need to learn more C++ so you can recognize what it means when your compiler points out these errors to you.
    Last edited by d_stranz; 11th April 2016 at 23:35.

Similar Threads

  1. Function not Declared in This Scope - error
    By marinskye in forum Qt Programming
    Replies: 3
    Last Post: 8th April 2016, 17:34
  2. Replies: 10
    Last Post: 22nd September 2010, 06:20
  3. Replies: 2
    Last Post: 16th July 2010, 07:17
  4. glutSolidSphere was not declared in this scope error
    By nuts_fever_007 in forum Qt Programming
    Replies: 2
    Last Post: 15th May 2009, 04:56
  5. error: 'connect' was not declared in this scope ??
    By Morea in forum Qt Programming
    Replies: 2
    Last Post: 14th January 2007, 15:27

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Qt is a trademark of The Qt Company.