Before the actual implementation, i wrote a small prototype code, and put a class constructor and ctor constructor in the same file, to see if the ctor would execute first, which is my actual implementation.
However, i am facing an error. Here is the code:
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include <iostream>
using namespace std;
extern "C" void startMe(void) __attribute__ ((constructor(1)));
extern "C" void ending(void) __attribute__ ((destructor));
class Test {
public:
Test()
{
cout << "This is test constructor" << endl;
}
};
int main()
{
Test();
printf("Now main called\n");
}
void startMe(void)
{
printf("Start me called before main\n");
}
void ending(void)
{
printf("Destructor called\n");
}
--
Output:
$ g++ constructor1.cc
constructor1.cc:10: error: wrong number of arguments specified for ‘constructor’ attribute
However, when i remove the constructor priority, it compiles and runs fine. That is, i do:
extern "C" void startMe(void) __attribute__ ((constructor));
Why is it so? How to give priority?
Please help me. My idea is "ctor" should be executed first, then the other (Test) constructor. The same reason, i have put ctor as a priority 1.