‘staticMetaObject’ is not a member

I tried to compile a code looking like this:

#ifndef CONTROLLER_H_
#define CONTROLLER_H_

#include<QObject>

class AbstractClass
{
public:
    virtual ~AbstractClass() {}
    virtual void update() = 0;
};

class Controller :
      public AbstractClass, public QObject
{
      Q_OBJECT

public:
      Controller();
      virtual ~Controller();
      virtual void update();

public slots:
      void m();
};

#endif /*CONTROLLER_H_*/

If you’re trying to compile it you get an error:

tmp/moc/moc_Controller.cpp:45: error: 'staticMetaObject' is not a member of 'AbstractClass'
tmp/moc/moc_Controller.cpp: In member function 'virtual void* Controller::qt_metacast(const char*)':
tmp/moc/moc_Controller.cpp:61: error: 'qt_metacast' is not a member of 'AbstractClass'
tmp/moc/moc_Controller.cpp: In member function 'virtual int Controller::qt_metacall(QMetaObject::Call, int, void**)':
tmp/moc/moc_Controller.cpp:66: error: 'qt_metacall' is not a member of 'AbstractClass'
make: *** [tmp/objects/moc_Controller.o] Error 1

The error is caused by a bad order of inheritance.

Instead of this

class Controller :
	public AbstractClass, public QObject
{
   ...

you should use this

class Controller :
	public QObject, public AbstractClass
{
   ...

 

  • Delicious
  • Digg
  • Technorati Favorites
  • Reddit
  • LinkedIn
  • Facebook
  • Spurl
  • Twitter
  • Webnews
  • YiGG
  • MySpace
  • Yahoo Bookmarks
  • FriendFeed
  • Google Bookmarks
  • LiveJournal
  • Share/Bookmark

error: stray ‘\160′ in program

I was experimenting with virtual and pure virtual methods in C++. I introduced an inline implementation for a pure method and then I couldn’t compile my code anymore.

I turned into the “show invisibles” mode and found the malefactor. The problem was an invisible character in the source file.

  • Delicious
  • Digg
  • Technorati Favorites
  • Reddit
  • LinkedIn
  • Facebook
  • Spurl
  • Twitter
  • Webnews
  • YiGG
  • MySpace
  • Yahoo Bookmarks
  • FriendFeed
  • Google Bookmarks
  • LiveJournal
  • Share/Bookmark

Pointer

Here are examples about how you can declare pointer in the programming language C++:

char* p;             //p is a pointer to char
char const* p;       //p is a pointer to const char
const char* p;       //p is a pointer to const char
char* const p;       //p is a const pointer to char
char const* const p; //p is a const pointer to const char
const char* const p; //p is a const pointer to const char

It might look strange by first reading :)

If you want to read more about pointers I refer you to a A Tutorial on Pointers and Arrays in C.

  • Delicious
  • Digg
  • Technorati Favorites
  • Reddit
  • LinkedIn
  • Facebook
  • Spurl
  • Twitter
  • Webnews
  • YiGG
  • MySpace
  • Yahoo Bookmarks
  • FriendFeed
  • Google Bookmarks
  • LiveJournal
  • Share/Bookmark