Имеются файлы:
main.cpp
:
#include <iostream>
#include "sqlite3/sqlite3.h"
#include "global.h"
#include "test.h"
using namespace std;
int main()
{
sqlite3_open16(L"blockchain2.db", &db_handler);
__sqlite3_print__
test();
system("pause");
sqlite3_close(db_handler);
return 1;
}
global.h
:
#pragma once
#include "sqlite3/sqlite3.h"
#define sqlite3_reset(stmt) sqlite3_reset(stmt), sqlite3_finalize(stmt)
static sqlite3* db_handler;
#define __sqlite3_print__ cout << db_handler << endl;
test.h
:
#pragma once
void test();
#include <iostream>
#include "global.h"
using namespace std;
void test() {
__sqlite3_print__
}
Что не так с этим гадом? Почему указатель из test.cpp
пуст?
такой результат невозможно получить с одной-единственной единицей трансляции. А у вас в вопросе она только одна - main.cpp. Единиц трансляции у вас на самом деле как минимум две.
Не совсем понял, о каких единицах трансляций говорится, если Вы про вывод на экран то в test.cpp есть вызов макроса.
Я пробовал extern
, но получается тоже самое. Еще раз весь код:
// --------- main.cpp:
#include <iostream>
#include "sqlite3/sqlite3.h"
#include "global.h"
#include "test.h"
using namespace std;
int main()
{
sqlite3* db_handler;
sqlite3_open16(L"sqlite3.db", &db_handler);
__sqlite3_print__
test();
system("pause");
sqlite3_close(db_handler);
return 1;
}
// --------- global.h:
#pragma once
#include "sqlite3/sqlite3.h"
#define sqlite3_reset(stmt) sqlite3_reset(stmt), sqlite3_finalize(stmt)
extern sqlite3* db_handler;
#define __sqlite3_print__ cout << db_handler << endl;
// --------- test.h:
#pragma once
void test();
// --------- test.cpp:
#include <iostream>
#include "global.h"
#include "test.h"
using namespace std;
sqlite3* db_handler;
void test() {
__sqlite3_print__
}
.cpp
файлом.