Using an external class in templated method from dll - c++

I'm trying to use my game engine into an external project. Everything works fine but I have a problem when I'm trying to create a custom component (That inherits from ABhaviour which is an abstract class representing a component that can be activated/disabled).
GameObject.h (exported with __declspec(dllexport))
// [...]
template <typename Class, typename ... Args>
std::shared_ptr<Class> GameObject::AddComponent(Args... args)
{
auto newComp = std::make_shared<Class>(std::forward<Args>(args)...);
m_components[typeid(*newComp).hash_code()] = newComp;
m_components[typeid(*newComp).hash_code()]->SetOwner(*this);
return newComp;
}
// [...]
In an other project (That use my game engine), I'm trying to create the custom ABehaviour :
PlayerController.h
#pragma once
#include <ElkGameEngine/Objects/Components/Behaviours/ABehaviour.h>
class PlayerController :ElkGameEngine::Objects::Components::Behaviours::ABehaviour
{
PlayerController() = default;
~PlayerController() = default;
void Update();
};
After that I add my custom component onto my "Player" GameObject :
Main.cpp
#include <ElkGameEngine/ElkGameEngine.h>
#include <ElkGameEngine/Objects/AObject.h>
#include <ElkGameEngine/Objects/Components/AComponent.h>
#include "PlayerController.h"
using namespace ElkGameEngine::Objects::Components;
using namespace ElkGameEngine::Objects::Components::Behaviours;
int main()
{
ElkGameEngine::Managers::EngineManager elkGameEngine;
elkGameEngine.GetSceneManager()->CreateScene("ElkCraft");
auto& player = elkGameEngine.GetSceneManager()->CreateEmptyGameObject("Player");
player.AddComponent<PlayerController>(); /* Here is the problem */
while (elkGameEngine.IsRunning())
{
elkGameEngine.PreUpdate();
elkGameEngine.PostUpdate();
}
return EXIT_SUCCESS;
}
Visual Studio is unhappy and print me this :
Severity Code Description Project File Line Suppression State
Error C2440 '<function-style-cast>': cannot convert from 'const std::shared_ptr<PlayerController>' to 'std::shared_ptr<ElkGameEngine::Objects::Components::AComponent>' ElkCraft c:\program files (x86)\microsoft visual studio\2017\community\vc\tools\msvc\14.12.25827\include\memory 1472
Error C2228 left of '.swap' must have class/struct/union ElkCraft c:\program files (x86)\microsoft visual studio\2017\community\vc\tools\msvc\14.12.25827\include\memory 1472
Output window :
1>------ Build started: Project: ElkCraft, Configuration: Debug x64 ------
1>Could Not Find C:\Users\adrie\Desktop\GROUP_2\PFA\ElkCraft\*.dll
1>main.cpp
1>c:\program files (x86)\microsoft visual studio\2017\community\vc\tools\msvc\14.12.25827\include\memory(1472): error C2440: '<function-style-cast>': cannot convert from 'const std::shared_ptr<PlayerController>' to 'std::shared_ptr<ElkGameEngine::Objects::Components::AComponent>'
1>c:\program files (x86)\microsoft visual studio\2017\community\vc\tools\msvc\14.12.25827\include\memory(1472): note: No constructor could take the source type, or constructor overload resolution was ambiguous
1>c:\users\adrie\desktop\group_2\pfa\elkengine\build\elkgameengine\include\elkgameengine\objects\gameobject.h(53): note: see reference to function template instantiation 'std::shared_ptr<ElkGameEngine::Objects::Components::AComponent> &std::shared_ptr<ElkGameEngine::Objects::Components::AComponent>::operator =<PlayerController>(const std::shared_ptr<PlayerController> &) noexcept' being compiled
1>c:\users\adrie\desktop\group_2\pfa\elkengine\build\elkgameengine\include\elkgameengine\objects\gameobject.h(55): note: see reference to function template instantiation 'std::shared_ptr<ElkGameEngine::Objects::Components::AComponent> &std::shared_ptr<ElkGameEngine::Objects::Components::AComponent>::operator =<PlayerController>(const std::shared_ptr<PlayerController> &) noexcept' being compiled
1>c:\users\adrie\desktop\group_2\pfa\elkcraft\sources\main.cpp(18): note: see reference to function template instantiation 'std::shared_ptr<PlayerController> ElkGameEngine::Objects::GameObject::AddComponent<PlayerController,>(void)' being compiled
1>c:\program files (x86)\microsoft visual studio\2017\community\vc\tools\msvc\14.12.25827\include\memory(1472): error C2228: left of '.swap' must have class/struct/union
1>Generating Code...
1>Compiling...
1>PlayerController.cpp
1>Generating Code...
1>Done building project "ElkCraft.vcxproj" -- FAILED.
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
I think that the problem come from the fact that my game engine (Which is a group of DLL) is exporting a templated method (AddComponent and other ones like GetComponent).
Is it possible to use a templated method from a dll with a class/struct template argument from the project using the dll ?
Am I doing something wrong ?
Do I need to specify something on my PlayerController to make it "known/usable" in the AddComponent method ?

Related

Does this class satisfy the Allocator requirement?

I made a custom allocator, but my code didn't compile on msvc and I'm not sure if my implementation satisfies the Allocator requirement (disregarding actual behavior of function implementations here). Here is a minimal example that reproduces the error on Visual Studio (16.11 P1 and 16.10):
#include <memory>
#include <vector>
template <typename T>
class Allocator
{
public:
using value_type = T;
[[nodiscard]]
T* allocate(std::size_t n)
{
return nullptr;
}
void deallocate(T* x, std::size_t n)
{
}
constexpr bool operator==(const Allocator& other) const noexcept
{
return true;
}
constexpr bool operator!=(const Allocator& other) const noexcept
{
return !(*this == other);
}
};
int main()
{
using Alloc = Allocator<int>;
using Vec = std::vector<int, Alloc>;
auto vec = Vec();
}
Godbolt isn't complaining for any major compiler but their msvc version is a little behind I think.
To me this looks like a compiler bug in msvc but I want to make sure before I open a ticket.
This is the compiler output:
Build started...
1>------ Build started: Project: Project1, Configuration: Debug x64 ------
1>main.cpp
1>C:\Program Files (x86)\Microsoft Visual Studio\2019\Preview\VC\Tools\MSVC\14.29.30129\include\vector(714,27): error C2440: 'static_cast': cannot convert from 'Allocator<int>' to 'Allocator<_Newfirst>'
1> with
1> [
1> _Newfirst=std::_Container_proxy
1> ]
1>C:\Program Files (x86)\Microsoft Visual Studio\2019\Preview\VC\Tools\MSVC\14.29.30129\include\vector(714,27): message : No constructor could take the source type, or constructor overload resolution was ambiguous
1>C:\Program Files (x86)\Microsoft Visual Studio\2019\Preview\VC\Tools\MSVC\14.29.30129\include\vector(711): message : while compiling class template member function 'std::vector<int,Alloc>::~vector(void) noexcept'
1>C:\code\dumpster\Project1\Project1\main.cpp(36): message : see reference to function template instantiation 'std::vector<int,Alloc>::~vector(void) noexcept' being compiled
1>C:\code\dumpster\Project1\Project1\main.cpp(36): message : see reference to class template instantiation 'std::vector<int,Alloc>' being compiled
1>C:\Program Files (x86)\Microsoft Visual Studio\2019\Preview\VC\Tools\MSVC\14.29.30129\include\vector(714,25): error C2530: '_Alproxy': references must be initialized
1>C:\Program Files (x86)\Microsoft Visual Studio\2019\Preview\VC\Tools\MSVC\14.29.30129\include\vector(715,1): error C3536: '_Alproxy': cannot be used before it is initialized
1>C:\Program Files (x86)\Microsoft Visual Studio\2019\Preview\VC\Tools\MSVC\14.29.30129\include\vector(715,9): error C2672: '_Delete_plain_internal': no matching overloaded function found
1>C:\Program Files (x86)\Microsoft Visual Studio\2019\Preview\VC\Tools\MSVC\14.29.30129\include\vector(715,1): error C2893: Failed to specialize function template 'void std::_Delete_plain_internal(_Alloc &,_Alloc::value_type *const ) noexcept'
1>C:\Program Files (x86)\Microsoft Visual Studio\2019\Preview\VC\Tools\MSVC\14.29.30129\include\xmemory(998): message : see declaration of 'std::_Delete_plain_internal'
1>C:\Program Files (x86)\Microsoft Visual Studio\2019\Preview\VC\Tools\MSVC\14.29.30129\include\vector(715,1): message : With the following template arguments:
1>C:\Program Files (x86)\Microsoft Visual Studio\2019\Preview\VC\Tools\MSVC\14.29.30129\include\vector(715,1): message : '_Alloc=int'
1>Done building project "Project1.vcxproj" -- FAILED.
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
Edit
I opened a bug ticket for the msvc devs.
It does not.
An allocator rebound to a different value type must be constructible from the original allocator - this is the A a(b) row in the requirements you linked.
Your type fails that requirement.

Thread std::invoke unknown type and failed to specialize function error

I tried to use thread at in function and send parameter as pointer class, i take errors that Error C2672 'std::invoke': no matching overloaded function found and Error C2893 Failed to specialize function template 'unknown-type std::invoke(_Callable &&,_Types &&...) noexcept(<expr>)'
I search a lot but only i found that about this error everyone forget to send parameter.I did not forget but i still have these errors.
My function as like below
Function Listen
void Listen(can* _c) {
while (_c->s != INVALID_SOCKET)
{
auto t = thread( &connect_tcp::Recv_data,_c->connection, _c->s,ref(_c->response), _c->signals ); //ERROR IS HERE
t.join();
}
}
Class can
class can {
public:
Cotp_connection cotp;
mms mms_obj;
connect_tcp* connection;
mms_response response;
LinkedList** list;
all_size_encoder size_encoder;
SOCKET s;
Signals* signals;
};
Class connect_tcp
class connect_tcp
{
public:
SOCKET ConnectWithTcp();
int send_data(SOCKET s, LinkedList** list,int &j);
connect_tcp();
connect_tcp(char* ip, int set_port);
void Close_tcp(SOCKET s);
void Recv_data(SOCKET s,mms_response &response, Signals *signals);
std::mutex mutex;
private:
SOCKET server;
SOCKADDR_IN addr;
int port;
WSADATA WSAData;
};
Function Recv_data
void connect_tcp::Recv_data(SOCKET s,mms_response &response,Signals *signals) {
LinkedList** list = new LinkedList * [1000];
uint8_t* buffer = new uint8_t [10000];
Sleep(1000);
std::lock_guard<std::mutex>guard(mutex);
recv(s, (char*)buffer, 10000, 0);
/*this->mutex.unlock();*/
decode_bytes(response,buffer, list,signals);
}
At auto t = thread( &connect_tcp::Recv_data,_c->connection, _c->s,ref(_c->response), _c->signals );
connect_tcp::Recv_data is my member function and _c->connection is my object that storage the member function, and other variables are function's parameters.
I tried everything that i saw and read but i got these errors everytime, i cannot find to solve this.
If you want to explore classes more than my writings. I can edit this post.
Building output
1>------ Build started: Project: kkkkk_v2, Configuration: Debug x64 ------
1>fake_main.cpp
1>C:\Users\serhan.erkovan\source\repos\kkkkk_v2\kkkkk_v2\byte_decode.h(78,94): warning C4138: '*/' found outside of comment
1>C:\Users\serhan.erkovan\source\repos\kkkkk_v2\kkkkk_v2\connect_tcp.cpp(45,3): warning C4551: function call missing argument list
1>D:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.23.28105\include\thread(40,14): error C2672: 'std::invoke': no matching overloaded function found
1>D:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.23.28105\include\thread(47): message : see reference to function template instantiation 'unsigned int std::thread::_Invoke<_Tuple,0,1>(void *) noexcept' being compiled
1>D:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.23.28105\include\thread(47): message : with
1>D:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.23.28105\include\thread(47): message : [
1>D:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.23.28105\include\thread(47): message : _Tuple=_Tuple
1>D:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.23.28105\include\thread(47): message : ]
1>D:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.23.28105\include\thread(53): message : see reference to function template instantiation 'unsigned int (__cdecl *std::thread::_Get_invoke<_Tuple,0,1>(std::integer_sequence<unsigned __int64,0,1>) noexcept)(void *)' being compiled
1>C:\Users\serhan.erkovan\source\repos\kkkkk_v2\kkkkk_v2\fake_main.cpp(291): message : see reference to function template instantiation 'std::thread::thread<int(__cdecl &)(SOCKET,int),can*&,void>(_Fn,can *&)' being compiled
1>C:\Users\serhan.erkovan\source\repos\kkkkk_v2\kkkkk_v2\fake_main.cpp(291): message : with
1>C:\Users\serhan.erkovan\source\repos\kkkkk_v2\kkkkk_v2\fake_main.cpp(291): message : [
1>C:\Users\serhan.erkovan\source\repos\kkkkk_v2\kkkkk_v2\fake_main.cpp(291): message : _Fn=int (__cdecl &)(SOCKET,int)
1>C:\Users\serhan.erkovan\source\repos\kkkkk_v2\kkkkk_v2\fake_main.cpp(291): message : ]
1>D:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.23.28105\include\chrono(669): message : see reference to class template instantiation 'std::chrono::duration<double,std::ratio<1,1>>' being compiled
1>D:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.23.28105\include\chrono(177): message : see reference to class template instantiation 'std::chrono::duration<__int64,std::nano>' being compiled
1>D:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.23.28105\include\chrono(647): message : see reference to class template instantiation 'std::chrono::time_point<std::chrono::steady_clock,std::chrono::steady_clock::duration>' being compiled
1>D:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.23.28105\include\thread(36,5): error C2893: Failed to specialize function template 'unknown-type std::invoke(_Callable &&,_Types &&...) noexcept(<expr>)'
1>D:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.23.28105\include\type_traits(1571): message : see declaration of 'std::invoke'
1>D:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.23.28105\include\thread(36,5): message : With the following template arguments:
1>D:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.23.28105\include\thread(36,5): message : '_Callable=int (__cdecl *)(SOCKET,int)'
1>D:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.23.28105\include\thread(36,5): message : '_Types={can *}'
1>Done building project "kkkkk_v2.vcxproj" -- FAILED.
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
The first argument to std::thread is a callable object which is defined like this:
template< class Function, class... Args >
explicit thread( Function&& f, Args&&... args );
This callable object must be callable with this syntax:
f()
But in your example you are passing a member function pointer to the construction of std::thread and the correct syntax to call a member function pointer is like this:
(calleeObject->*fp)()
So you cannot pass a member function pointer to the constructor of std::thread. The easy way to solve it would be using a lambda as your callable object:
std::thread([=_c]()
{
_c->connection->Recv_data(_c->s, ref(_c->response), _c->signals);
});
or you can use std::mem_fn adapter and include your callee object in your parameters list too as you did it in your own code:
std::thread(std::mem_fn(&connect_tcp::Recv_data), _c->connection, _c->s, ref(_c->response), _c->signals);

Invoking std::thread with class operator()() that has CWinThread as base fails

Background:
My project is C++ MFC. But I am writing the code using modern C++ as the standard evolves. Currently, I invoke threads sometimes using std::thread (later code) and sometimes the MFC CreateThread complete with required waitForSingleObject and thread priority parameter. Clearly, the std::thread is more elegant and therefore more maintainable. It is important to over time make the code consistent and drop old idioms where possible.
Problem:
But invoking std::thread with a class Baz in sample code below that has CWinThread as its base, fails to find a std::thread constructor.
Sample Code:
struct Caz {};
struct Baz : public CWinThread // works if base is Caz
{
void operator()() {}
};
std::shared_ptr< Baz > b;
b = std::make_shared< Baz >();
std::thread bazThread( *b ); // error: can't find a constructor when CWinThread is base, but can for Caz as base
When the base class is CWinThread it fails to resolve, but when the base class is Caz it works fine. Both Caz and CWinThread have default constructors.
Why is CWinThread making it fail?
Edit1:
The error message set is:
1>C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.23.28105\include\memory(2057,35): error C2665: 'std::tuple::tuple': none of the 2 overloads could convert all the argument types
1>C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.23.28105\include\tuple(321,5): message : could be 'std::tuple::tuple(std::tuple &&)'
1>C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.23.28105\include\tuple(320,5): message : or 'std::tuple::tuple(const std::tuple &)'
1>C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.23.28105\include\memory(2056,59): message : while trying to match the argument list '(_Ty2)'
1>C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.23.28105\include\memory(2056,59): message : with
1>C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.23.28105\include\memory(2056,59): message : [
1>C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.23.28105\include\memory(2056,59): message : _Ty2=Baz
1>C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.23.28105\include\memory(2056,59): message : ]
1>C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.23.28105\include\thread(53): message : see reference to function template instantiation 'std::unique_ptr<_Tuple,std::default_delete<_Ty>> std::make_unique<_Tuple,_Ty2&,0>(_Ty2 &)' being compiled
1>C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.23.28105\include\thread(53): message : with
1>C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.23.28105\include\thread(53): message : [
1>C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.23.28105\include\thread(53): message : _Ty=_Tuple,
1>C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.23.28105\include\thread(53): message : _Ty2=Baz
1>C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.23.28105\include\thread(53): message : ]
1>E:\Hiveware\trunk\Windows\hives\Hiveware\SdcdcHiveware\GrammarSdcdcHiveware.cpp(153): message : see reference to function template instantiation 'std::thread::thread<_Ty2&,,void>(_Fn)' being compiled
1>E:\Hiveware\trunk\Windows\hives\Hiveware\SdcdcHiveware\GrammarSdcdcHiveware.cpp(153): message : with
1>E:\Hiveware\trunk\Windows\hives\Hiveware\SdcdcHiveware\GrammarSdcdcHiveware.cpp(153): message : [
1>E:\Hiveware\trunk\Windows\hives\Hiveware\SdcdcHiveware\GrammarSdcdcHiveware.cpp(153): message : _Ty2=Baz,
1>E:\Hiveware\trunk\Windows\hives\Hiveware\SdcdcHiveware\GrammarSdcdcHiveware.cpp(153): message : _Fn=Baz &
1>E:\Hiveware\trunk\Windows\hives\Hiveware\SdcdcHiveware\GrammarSdcdcHiveware.cpp(153): message : ]
1>Done building project "SdcdcHiveware.vcxproj" -- FAILED.
Edit2:
// FUNCTION TEMPLATE make_unique
template <class _Ty, class... _Types, enable_if_t<!is_array_v<_Ty>, int> = 0>
_NODISCARD unique_ptr<_Ty> make_unique(_Types&&... _Args) { // make a unique_ptr
return unique_ptr<_Ty>(new _Ty(_STD forward<_Types>(_Args)...));
}
Tentative answer unless someone finds a workaround.
std::thread cannot be used in MFC projects for class types that inherit from CWinThread, also called user threads for which sample code may be found at Creating Threads.
For traditional windows worker threads invoking std::thread instead works fine.

Error C2664 when trying to create unique_ptr

I'm trying to figure out a problem I have in my project, and I have simplified it down to this little bit of code that generates the C2664 error. I don't understand the error message, could anyone help me to understand? I've googled, and I've looked through 2 C++ books and this code is exactly what is listed in them, but it does not work for me.
Thanks.
#include <memory>
struct A
{
int b;
};
int main(int argc, char ** argv)
{
A a;
std::unique_ptr<A> a_ptr = std::make_unique<A>(new A);
return 0;
}
And here is the error:
1>------ Build started: Project: Project1, Configuration: Debug Win32 ------
1>main.cpp
1>c:\program files (x86)\microsoft visual studio\2017\community\vc\tools\msvc\14.12.25827\include\memory(2585): error C2664: 'A::A(const A &)': cannot convert argument 1 from 'A *' to 'A &&'
1>c:\program files (x86)\microsoft visual studio\2017\community\vc\tools\msvc\14.12.25827\include\memory(2584): note: Reason: cannot convert from 'A *' to 'A'
1>c:\program files (x86)\microsoft visual studio\2017\community\vc\tools\msvc\14.12.25827\include\memory(2584): note: No constructor could take the source type, or constructor overload resolution was ambiguous
1>d:\users\aksel\documents\visual studio 2017\projects\project1\project1\main.cpp(21): note: see reference to function template instantiation 'std::unique_ptr<A,std::default_delete<_Ty>> std::make_unique<A,A*,0>(A *&&)' being compiled
1> with
1> [
1> _Ty=A
1> ]
1>Done building project "Project1.vcxproj" -- FAILED.
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
The argument to make_unique is the argument to a T constructor, not a pointer to a T instance, just use the regular unique_ptr ctor if you already have a pointer to a T.

C++ in Visual Studio 2013 - <Class> is undefined

I'm very new to C++/VS and might missing something in the code/configuration of my project.
In my solution I have 2 projects:
first is NTL which I downloaded from https://bitbucket.org/ben_key/ntl, and compiled to a static library NTL.lib.
a 'test' project in which: (1) I added the header files by specifying their directory in the properties->C++->Additional Include Files, (2) in the properties->Linker->Input->Additional Dependencies I added "NTL.lib" (3)copied the NTL.lib file to be in the same directory as the main cpp file of the 'test' project.
My cpp only contains:
#include <NTL/GF2X.h>
int main() {
GF2X P;
return 1;
}
The build gives the output:
1>------ Build started: Project: test, Configuration: Release Win32 ------
1>C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\V120\Microsoft.CppBuild.targets(388,5): warning MSB8028: The intermediate directory (Release\) contains files shared from another project (ntl-test.vcxproj). This can lead to incorrect clean and rebuild behavior.
1> QuickTest.cpp
1>..\tests\QuickTest.cpp(43): warning C4101: 'n' : unreferenced local variable
1>D:\studies\Thesis\NTL-Ben-Key\Include\NTL/vector.h(79): warning C4291: 'void *operator new(size_t,_ntl_vector_placement)' : no matching operator delete found; memory will not be freed if initialization throws an exception
1> D:\studies\Thesis\NTL-Ben-Key\Include\NTL/vector.h(36) : see declaration of 'operator new'
1> D:\studies\Thesis\NTL-Ben-Key\Include\NTL/vector.h(319) : see reference to function template instantiation 'void NTL::BlockConstruct<T>(T *,long)' being compiled
1> with
1> [
1> T=NTL::zz_p
1> ]
1> D:\studies\Thesis\NTL-Ben-Key\Include\NTL/vector.h(291) : while compiling class template member function 'void NTL::Vec<NTL::zz_p>::DoSetLength(long)'
1> D:\studies\Thesis\NTL-Ben-Key\Include\NTL/vector.h(115) : see reference to function template instantiation 'void NTL::Vec<NTL::zz_p>::DoSetLength(long)' being compiled
1> D:\studies\Thesis\NTL-Ben-Key\Include\NTL/vec_lzz_p.h(14) : see reference to class template instantiation 'NTL::Vec<NTL::zz_p>' being compiled
1> MyTest.cpp
1>MyTest.cpp(4): error C2065: 'GF2X' : undeclared identifier
1>MyTest.cpp(4): error C2146: syntax error : missing ';' before identifier 'P'
1>MyTest.cpp(4): error C2065: 'P' : undeclared identifier
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
It is really a simple thing and I didn't figured out what I'm missing.
From NTL/include/NTL/ tools.h:
#define NTL_NAMESPACE NTL
#define NTL_OPEN_NNS namespace NTL_NAMESPACE {
#define NTL_CLOSE_NNS }
So when the preprocessor encounters NTL_OPEN_NNS, as is the case in the include file GF2X.h, it expands it to namespace NTL meaning the GF2X class is declared insided the namespace NTL. In order to use it you need to fully qualify it as NTL::GF2X or use using namespace NTL for discussion about which one look here for example.
Likewise at the end of GF2X.h there is a closing bracket after expanding NTL_CLOSE_NNS