How to add a class to the tree

Amittai Aviram amittai.aviram@yale.edu
Sat Aug 1 13:57:00 GMT 2009


On Aug 1, 2009, at 5:11 AM, Klesk wrote:

> Let's say I have code like this:
>
> SampleClass object;
>
> which of course fails to compile because there is no SampleClass.
>
> How to programmically create a class named SampleClass to make it
> possible to complie ?
>
>
> --  
> Klesk


Hi, Kiesk!

#include <iostream>

class SampleClass {
  private:
    int id;
  public:
   SampleClass() {
    id = 42;
  }
  int get_id() {
    return id;
  }
};

int main(int argc, char ** argv) {

  SampleClass object;
  std::cout << object.get_id() << std::endl;
  return EXIT_SUCCESS;
}


Do you mean something else?  By "programmatically create," do you mean  
create dynamically at runtime, as you would using the reflection  
mechanisms of Java or C#?

Thanks.


Amittai Aviram
Graduate Student in Computer Science
Yale University
646 483 2639
amittai.aviram@yale.edu
http://www.amittai.com



More information about the Gcc-help mailing list