Results 1 to 3 of 3

Thread: extern array in qt

  1. #1
    Join Date
    Oct 2014
    Posts
    71
    Thanks
    13
    Qt products
    Qt5
    Platforms
    Windows

    Question extern array in qt

    Hello
    I have class where i declared an array and i want to use the value of same array in other class.
    I don't want to create any object to access the array .so i tried declare the array as extern.
    code as below
    Qt Code:
    1. class emu
    2. {
    3. UCHAR D0[8];
    4. void decimarconverter(UCHAR *answer)
    5. {
    6.  
    7. for(int i =0;i<=7;i++)
    8. {
    9. D0[i] =answer[0]%2;
    10. answer[0] = answer[0]/2;
    11. qDebug()<<"Binary number is D0"<<D0[i];
    12. }
    13. }
    14.  
    15. class emu1
    16. {
    17. extern UCHAR D0[]
    18. void show()
    19. {
    20. for(int i =0;i<=7;i++)
    21. qDebug()<<D0[i]<<"Value";
    22. }
    23. }
    To copy to clipboard, switch view to plain text mode 

    But i am getting an error
    error: 'UCHAR' does not name a type
    extern UCHAR D0[];
    Can any one let me know why i am getting the error

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: extern array in qt

    You need to include the file which defines UCHAR type (it's either a typedef or a macro).
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  3. #3
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: extern array in qt

    As wysota wrote, your compile error is easy.

    But the extern doesn't help you at all here.
    emu:0 is a member of emu, each instance of emu has its own. which one would you think that "extern" would refer to?

    emu1 is a different class. instances of emu1 can't access private members of emu objects.

    Cheers,
    _

Similar Threads

  1. Declaring a class as extern
    By ehnuh in forum General Programming
    Replies: 6
    Last Post: 9th November 2012, 01:14
  2. Problems compiling when using an extern
    By aarelovich in forum Qt Programming
    Replies: 2
    Last Post: 24th June 2011, 12:32
  3. Extern Variable linkage error
    By mebingj in forum Newbie
    Replies: 3
    Last Post: 26th January 2011, 12:06
  4. extern QWidgetList *qt_modal_stack
    By Alex_123 in forum Qt Programming
    Replies: 5
    Last Post: 20th December 2008, 12:24
  5. extern class
    By zorro68 in forum Qt Programming
    Replies: 2
    Last Post: 5th October 2007, 21:08

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
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.