dimanche 8 décembre 2019

Are members functions available during compile time in C++?

Trying to compile the following using c++11 standards (using constexpr) completed successfully:

class test{
 public:
 int getId(){
   constexpr int id = 5;
   return id;
 }
};

During compile time, test doesn't exist yet, however, the above code compiles just fine. If test doesn't exist yet then how can getId exist during compile time?

Full working example:

#include <iostream>

class test{
 public:
 int getId(){
   constexpr int id = 5;
   return id;
 }
};

int main(){
 test t;
 std::cout << t.getId() << std::endl;
 return 0;
}

Aucun commentaire:

Enregistrer un commentaire