Results 1 to 3 of 3

Thread: no match for 'operator=' in...

  1. #1
    Join Date
    Apr 2010
    Posts
    2
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Windows

    Default no match for 'operator=' in...

    Hi

    I'm trying to make a version of minesweeper in Qt4. In order to do this i have subclassed QPushButton to make a new class, MinesveiperButton. This seems to work fine, however when i try to make a new grid, using a 2-dimentional array and fill it with MinesveiperButtons i get this error:
    C:/C++ Qt/Minesveiper/v3/minesveiper.cpp:52: error: no match for 'operator=' in '*((*(((Minesveiper*)this)->Minesveiper::mask + ((unsigned int)(((unsigned int)i) * 4u)))) + ((unsigned int)(((unsigned int)j) * 28u))) = (operator new(28u), (<statement>, ((MinesveiperButton*)<anonymous>)))'
    This is Minesveiper.h:
    Qt Code:
    1. #ifndef MINESVEIPER_H
    2. #define MINESVEIPER_H
    3.  
    4. #include <QMainWindow>
    5. #include <QGridLayout>
    6. #include "MinesveiperButton.h"
    7.  
    8. namespace Ui {
    9. class Minesveiper;
    10. }
    11.  
    12. class Minesveiper : public QMainWindow {
    13. Q_OBJECT
    14. public:
    15. Minesveiper(QWidget *parent = 0);
    16. ~Minesveiper();
    17.  
    18. void makeBoard();
    19. void startSpill(int h, int w, int m);
    20.  
    21. public slots:
    22. void startEnkeltSpill();
    23.  
    24. protected:
    25. void changeEvent(QEvent *e);
    26.  
    27. private:
    28. Ui::Minesveiper *ui;
    29.  
    30. int mHeight;
    31. int mWidth;
    32. int mines;
    33. int antOpen;
    34. int **board;
    35. MinesveiperButton **mask;
    36. };
    37.  
    38. #endif // MINESVEIPER_H
    To copy to clipboard, switch view to plain text mode 

    and this is MinesveiperButton.h:
    Qt Code:
    1. #ifndef MINESVEIPERBUTTON_H
    2. #define MINESVEIPERBUTTON_H
    3.  
    4. #include <QtGui/qpushbutton.h>
    5. #include "minesveiper.h"
    6.  
    7. class MinesveiperButton : public QPushButton {
    8. Q_OBJECT
    9. public:
    10.  
    11. MinesveiperButton(int x, int y);
    12. MinesveiperButton();
    13. ~MinesveiperButton();
    14.  
    15. void open();
    16. void flag();
    17. void setIcon();
    18.  
    19. //MinesveiperButton & operator=(const MinesveiperButton &rhs);
    20.  
    21. private:
    22. int xpos;
    23. int ypos;
    24.  
    25. };
    26.  
    27. #endif // MINESVEIPERBUTTON_H
    To copy to clipboard, switch view to plain text mode 

    and finally implementation of Minesveiper::makeBoard() from Minesveiper.cpp, which is where i get the error:
    Qt Code:
    1. void Minesveiper::makeBoard() {
    2. /*
    3.   Deletes board and mask, and makes new arrays.
    4.   Empties grid and adds new MinesveiperButtons to grid.
    5. */
    6. delete [] board;
    7. delete [] mask;
    8.  
    9. // Empty grid
    10. int ant = grid.count();
    11. for(int i = 0; i < ant; i++) {
    12. delete grid.itemAt(i);
    13. }
    14.  
    15. // Make new arrays
    16. board = new int *[mHeight];
    17. mask = new MinesveiperButton *[mHeight];
    18. for(int i = 0; i < mHeight; i++) {
    19. board[i] = new int[mWidth];
    20. mask[i] = new MinesveiperButton[mWidth];
    21. for(int j = 0; j < mWidth; j++) {
    22. board[i][j] = 0;
    23. mask[i][j] = new MinesveiperButton(j, i);
    24. grid.addWidget(&mask[i][j], i, j);
    25. }
    26. }
    27. }
    To copy to clipboard, switch view to plain text mode 

    line 52 is numbered 23 here..

    Can someone help me with this? I thought =operator didn't need overloading. Does it?
    Just tell me if you want to view more of the code..

  2. #2
    Join Date
    Feb 2007
    Location
    Karlsruhe, Germany
    Posts
    469
    Thanks
    17
    Thanked 90 Times in 88 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: no match for 'operator=' in...

    Hi there!

    MinesveiperButton **mask will give you a pointer to a pointer of type MinesveiperButton. If you use twodimensional-array indexing you end up just with MinesveiperButton, not MinesveiperButton*!

    You should use a higherlevel approach like QList<QList<MinesveiperButton* >> mask; to avoid such problems!

    But why do you want to keep the extra list anyway? You can use the Gridlayout:

    MinesveiperButton* button = qobject_cast<MinesveiperButton*>(grid.itemAtPositi on(i,j).widget());

    HIH

    Johannes

  3. The following user says thank you to JohannesMunk for this useful post:

    toss (14th April 2010)

  4. #3
    Join Date
    Apr 2010
    Posts
    2
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: no match for 'operator=' in...

    Thanks, that is a great idea! Worked good!

Similar Threads

  1. Replies: 3
    Last Post: 23rd December 2009, 17:18
  2. Replies: 1
    Last Post: 21st September 2009, 08:30
  3. Match Height between 2 Adjoining QTableViews
    By ChrisW67 in forum Qt Programming
    Replies: 0
    Last Post: 14th April 2009, 04:52
  4. Match the text beetween two string
    By dreamer in forum Qt Programming
    Replies: 4
    Last Post: 20th May 2008, 15:48
  5. No match for operator>>
    By Salazaar in forum Newbie
    Replies: 18
    Last Post: 12th June 2007, 18:48

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.