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. Can we use MACROS for a class declaration ?
Forum Updated to NodeBB v4.3 + New Features

Can we use MACROS for a class declaration ?

Scheduled Pinned Locked Moved General and Desktop
3 Posts 3 Posters 816 Views 1 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.
  • D Offline
    D Offline
    drdas
    wrote on last edited by
    #1

    For example,

    #define CLASSNAME class A { public: A() {} static void SomeFunc(){} };

    Is this the right way to do ?
    I have tried doing this but after this decalration i cannot see/access class A in the intellisense.
    and i also i want to access A::SomeFunc() in other place.

    1 Reply Last reply
    0
    • C Offline
      C Offline
      ChrisW67
      wrote on last edited by
      #2

      You need to separate class A into a header containing the declaration and a file containing the implementation. In the other class implementation that needs A::SomeFunc() you should include the new header.

      @
      // a.h
      #ifndef CLASSA
      #define CLASSA
      class A {
      public:
      A();
      static void SomeFunc();
      };
      #endif // CLASSA
      @
      @
      // a.cpp
      A::A() { }

      void A::SomeFunc() { }
      @
      @
      // b.cpp
      #include "a.h"

      ...
      A::SomeFunc();
      ...
      @

      This is generic C++ and not Qt related.

      1 Reply Last reply
      0
      • JeroentjehomeJ Offline
        JeroentjehomeJ Offline
        Jeroentjehome
        wrote on last edited by
        #3

        You could remove the A.cpp file if you define your functions in your class definition. (this is done by QtDesigner in the _ui.h files). This way you will only need to include the header file.
        When you want to use the function you will also need an object (else the function should be made static and placed in a cpp file!)
        So the code ChrisW67 mentioned will only work with the A::SomeFunc() call being static!!

        Greetz, Jeroen

        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