Separate compilation: Can't take address for reference type value defalloc.h(130)

Hello!

I want to split my program into several files.

I have created 3 files:

file1.h:

#ifndef _file1
#define _file1

#include <iostream>
#include <vector>

struct StructTest
{
	double x;
	double y;
	StructTest(double x, double y);
};
std::vector<StructTest> initialize();


#endif // _file1

file1.cpp:

#include "file1.h"
StructTest::StructTest(double x, double y) : x(x), y(y)
{
}

std::vector<StructTest> initialize()
{
	std::vector<StructTest> struct_test_vec_obj;
	for (int i = 0; i < 10; i++)
	{
		struct_test_vec_obj.push_back(StructTest(i, i * 10));
	}
	return struct_test_vec_obj;
}

Source.cpp:

#include <iostream>
#include "file1.h"

using namespace std;


int main()
{
	std::vector<StructTest> struct_test_vec_obj = initialize();
	for (int i = 0; i < struct_test_vec_obj.size(); i++)
	{
		cout << "x = " << struct_test_vec_obj[i].x << "; y = " << struct_test_vec_obj[i].y << endl;
	}

	//system("pause");
	return 0;
}

This code works in VS2013.

In order to compile this code in root I have added in rootlogon.c this code:

{
gROOT->ProcessLine(".L D:\\git_repositories\\Parser_signal_finder\\VS2013\\Parser\\Test\\file1.h");
gROOT->ProcessLine(".L D:\\git_repositories\\Parser_signal_finder\\VS2013\\Parser\\Test\\file1.cpp");
gROOT->ProcessLine(".L D:\\git_repositories\\Parser_signal_finder\\VS2013\\Parser\\Test\\Source.cpp");
}

I launch my code by the next command and have an error:

root -l
main()
Error: Can't take address for reference type value defalloc.h(130)

My version is

ROOT 5.34/36 (v5-34-36@v5-34-36, Apr 05 2016, 10:25:45 on win32)
CINT/ROOT C/C++ Interpreter version 5.18.00, July 2, 2010

Could you help?
Thank you in advance.

Best regards, Vladislav.

Hi,

Use ACLiC:

C:\Users\bellenot\rootdev\Forum\Vladislav\test>root -l
root [0] gROOT->ProcessLine(".L file1.cpp+");
Info in <TWinNTSystem::ACLiC>: creating shared library C:\Users\bellenot\rootdev\Forum\Vladislav\test\file1_cpp.dll
23020101_cint.cxx
file1_cpp_ACLiC_dict.cxx
   Creating library C:\Users\bellenot\rootdev\Forum\Vladislav\test\file1_cpp.lib and object C:\Users\bellenot\rootdev\Forum\Vladislav\test\file1_cpp.exp
root [1] gROOT->ProcessLine(".L source.cpp+");
Info in <TWinNTSystem::ACLiC>: creating shared library C:\Users\bellenot\rootdev\Forum\Vladislav\test\source_cpp.dll
27520107_cint.cxx
source_cpp_ACLiC_dict.cxx
   Creating library C:\Users\bellenot\rootdev\Forum\Vladislav\test\source_cpp.lib and object C:\Users\bellenot\rootdev\Forum\Vladislav\test\source_cpp.exp
root [2] main()
x = 0; y = 0
x = 1; y = 10
x = 2; y = 20
x = 3; y = 30
x = 4; y = 40
x = 5; y = 50
x = 6; y = 60
x = 7; y = 70
x = 8; y = 80
x = 9; y = 90
(int)0
root [3]

Cheers, Bertrand.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.