WPM not accepting typenames - wpm

So basically i was writing a simple programm that would spot ennemies on the radar, however, when trying to use this line :
Features::WPM<int>(dwCurrentEntity + m_bSpotted, 1);
i get an error "unresolved external symbol "void _cdecl Features::WPM(unsigned long, int)" (?? $WPM#H#Features##YAXKH#Z)"
could anyone give me hints or help me please.
This is what i defined WPM as :
//Features.cpp
template<typename T> void Features::WPM(SIZE_T address, T buffer)
{
WriteProcessMemory(hProcess, (void*)address, &buffer, sizeof(T), nullptr);
}
//Features.h
template<typename T> void WPM(SIZE_T address, T buffer);

Related

c++ optional/default argument

I have defined a method with an optional/defaulted last argument called noAutoResolve as follows:
typedef std::shared_ptr<IMessage> TMessagePtr;
class NetworkService : public IConnectionManagerDelegate, public net::IStreamDelegate
{
public:
void send_message(std::string identity, msg::TMessagePtr msg, QObject* window, std::function<void(int, std::shared_ptr<msg::IMessage> msg)> fn, bool noAutoResolve = false);
}
and later:
void NetworkService::send_message(std::string endpoint, msg::TMessagePtr msg, QObject* window, std::function<void(int res, std::shared_ptr<msg::IMessage> msg)> fn, bool noAutoResolve)
{
}
The linker is now unhappy about unresolved externals in the following line where I intentionally omitted the last argument:
service_->send_message(endpoint_, msg, this, [this](int result, msg::TMessagePtr msg){
// .....
});
Is that not possible in c++?
Error LNK1120 1 unresolved externals QTServer QTServer.exe 1
Error LNK2019 unresolved external symbol "public: void __thiscall NetworkService::send_message(class std::basic_string,class std::allocator >,class std::shared_ptr,class QObject *,class std::function)>)" (?send_message#NetworkService##QAEXV?$basic_string#DU?$char_traits#D#std##V?$allocator#D#2##std##V?$shared_ptr#UIMessage#msg###3#PAVQObject##V?$function#$$A6AXHV?$shared_ptr#UIMessage#msg###std###Z#3##Z) referenced in function "public: void __thiscall QTWindow::ExecuteCommand(void)" (?ExecuteCommand#QTWindow##QAEXXZ) QTServer QTWindow.obj 1
The fn parameter of your function is type of std::function<void(int, std::shared_ptr<msg::IMessage> msg)>. However, the lambda you are passing is:
[this](int result, msg::TMessagePtr msg){
// .....
}
This function has the signature of void(int, msg::TMessagePtr), so if there is no conversion from std::shared_ptr<msg::IMessage> to msg::TMessagePtr, the code cannot compile.
Your problem is therefore not about the optional parameter. For a quick fix, if you have access to a C++14 compiler, try getting the lambda parameters as auto:
[this](auto result, auto msg){
// .....
}

C++ lnk error 2019 unresolved external symbol virtual errors because of an interface...(?)

Im having problems with making a good interface and use it...
My setup overview:
An "interface" GraphicsLibrary.H...
virtual void drawPoint(const Point& p, unsigned char r, unsigned char g, unsigned char b, double pointSize);
with an "empty" GraphicsLibrary.ccp! because its an interface, so "OpenGL" is an graphics library... so i have an OpenGL.CPP with:
void GraphicsLibrary::drawPoint(const Point& p, unsigned char r, unsigned char g, unsigned char b, double pointSize)
{
//some code
}
which has ofcourse an "empty" OpenGL.h (since his header file is the GraphicsLibrary.h)
then i have a class with more specific functions that uses OpenGL, and uses those base drawing functions... (OpenGLVis_Enviroment.cpp):
OpenGL ogl;
void drawObstacleUnderConstruction(Obstacle::Type type, const vector<Point>& points)
{
for( //etcetc )
ogl.drawPoint(*it, 255, 255, 255, 3.0);
}
BUT i also have a main that uses some OpenGL functions...
so the main has also:
OpenGL openGL;
openGL.drawText(something);
but now i have a lot of those errors (i have the same with all the other functions):
1>OpenGLVis_Environment.obj : error LNK2019: unresolved external symbol "public: virtual void __thiscall GraphicsLibrary::drawPoint(struct Point const &,unsigned char,unsigned char,unsigned char,double)" (?drawPoint#GraphicsLibrary##UAEXABUPoint##EEEN#Z) referenced in function "void __cdecl DrawingFunctions::drawObstacleUnderConstruction(enum Obstacle::Type,class std::vector<struct Point,class std::allocator<struct Point> > const &)" (?drawObstacleUnderConstruction#DrawingFunctions##YAXW4Type#Obstacle##ABV?$vector#UPoint##V?$allocator#UPoint###std###std###Z)
Is this because i use "GraphicsLibrary::drawPoint..." ? I am searching online for ages, but it's hard to find a lot of examples about interfaces.. and how to work with them...
Thanks in advance guys
The linker complains about DrawingFunctions::drawObstacleUnderConstruction and you defined void drawObstacleUnderConstruction, which is a free function.
Qualify the name when you define the function.
void DrawingFunctions::drawObstacleUnderConstruction(Obstacle::Type type, const vector<Point>& points)
{
for( //etcetc )
ogl.drawPoint(*it, 255, 255, 255, 3.0);
}

Unresolved external symbol on operator++ in template [duplicate]

This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
Why do I get “unresolved external symbol” errors when using templates?
I am making a linkedList. I am using an external iterator. The Iterator class is a template, and I am implementing my methods in the Iterator.h.
Here is the template:
#pragma once
#include "Node.h"
namespace list_1
{
template<typename T>
class Iterator
{
public:
Iterator<T> (Node<T> *np);
void operator++();
bool is_item();
T operator* ();
private:
Node<T>* n;
};
template<typename T>
Iterator<T>::Iterator (Node<T> *np)
{
}
template<typename T>
void Iterator<T>::operator++()
{
}
template<typename T>
bool Iterator<T>::is_item()
{
return false;
}
template<typename T>
T Iterator<T>::operator* ()
{
}
}
I get this error message when I try to compile: 1>list_test.obj : error LNK2019: unresolved external symbol "public: void __thiscall list_1::Iterator<double>::operator++(void)"
Plus about seven other similar errors in the whole project.
Am I doing something wrong here? Or is it something else I am doing wrong?
Thanks!
If I read your error message correctly, you Iterator takes Node<T> as input, however you are applying double to it which is not applicable. To support non-Node<T> type, you need to specialize Iterator<T>.
public: void __thiscall list_1::Iterator<double>::operator++(void)"
^^^^^

Multiple class in a list c++ [duplicate]

This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
Why can templates only be implemented in the header file?
Main class
int main() {
initCarList();
}
void initCarList() {
List<Car> carList;
Car c1 = Car("Toyota", "Bettle", 5);
carList.add(c1);
Car c2 = Car("Mercedes", "Bettle", 7);
carList.add(c2);
Car c3 = Car("FireTruck", "Large Van", 20);
carList.add(c3);
Car c4 = Car("Puma", "Saloon Car", 10);
carList.add(c4);
}
List class
#include "List.h"
#include <iostream>
using namespace std;
template <typename ItemType>
class List {
private:
ItemType itemList[10];
int size;
public:
List();
void add(ItemType);
void del(int index);
bool isEmpty();
ItemType get(int);
int length();
};
template<typename ItemType>
List<ItemType>::List() {
size = 0;
}
template<typename ItemType>
void List<ItemType>::add(ItemType item) {
if(size < MAX_SIZE) {
itemList[size] = item;
size++;
} else {
cout << typename << " list is full.\n";
}
}
I got errors like these
Error 3 error LNK2019: unresolved external symbol "public: void
__thiscall List::add(class Car)" (?add#?$List#VCar####QAEXVCar###Z) referenced in function "void
__cdecl initCarList(void)" (?initCarList##YAXXZ) C:\Users\USER\Desktop\New
folder\DSA_Assignment\main.obj DSA_Assignment
Did I do anything wrongly in my code? NEED HELP THANKS!
There is a syntax error (cout << typename ) in your code. I don't know how you got the linker error. May be its not being compiled at all.
otherwise its okay http://ideone.com/PGWGZu
Clearly you did as it doesn't work! Flippancy aside, let's take a look at the error message bit by bit:
Error 3 error LNK2019: unresolved external symbol
So this is a linkage error. The linker is trying to put together the units that were individually compiled together, but in this case it can't find an external symbol - usually a function or variable name.
"public: void __thiscall List::add(class Worker)" (?add#?$List#VWorker####QAEXVWorker###Z)
This is the full signature of the function that you're missing. It's name manged unfortunately but with your context knowledge of the code that you're writing, you should be able to tell that it's:
void List::add(Worker)
The next bit ...
referenced in function "void __cdecl initWorkerList(void)" (?initWorkerList##YAXXZ) C:\Users\USER\Desktop\New folder\DSA_Assignment\main.obj DSA_Assignment
... is telling you where the problem is happening, i.e where in the code it's trying to link, there is a reference to the missing function. Again, after demangling it's in:
void initWorkerList()
As you can see, with a bit of graft, you can determine exactly what you've done wrong here. Hope this helps.

C++ Template/Generics error

I have a simple function setup to check if a value is in a std::vector, and I would like to use a 'Template' to beable to use the function with all classes.
Some definitions
std::vector<ItemID_t> *spareItems;
ItemID_t newItem;//note this is an enumeration value
The function works perfectly if I call with
bool b = !vectorContains(*spareItems,newItem);
and the function looks like
bool vectorContains(std::vector<ItemID_t> &vector,const ItemID_t& value){
return std::find(vector.begin(), vector.end(), value)!=vector.end();
}
but if I try to implement generics with the call
bool b = !vectorContains<ItemID_t>(*spareItems,newItem);
and the function definition
template <class T>
bool vectorContains(std::vector<T> &vector,const T& value){
return std::find(vector.begin(), vector.end(), value)!=vector.end();
}
It fails in the second example and gives me this linker error
error LNK2019: unresolved external symbol "bool __cdecl turtle::vectorContains<enum turtle::ItemID_t>(class std::vector<enum turtle::ItemID_t,class std::allocator<enum turtle::ItemID_t> > &,enum turtle::ItemID_t const &)" (??$vectorContains#W4ItemID_t#turtle###turtle##YA_NAAV?$vector#W4ItemID_t#turtle##V?$allocator#W4ItemID_t#turtle###std###std##ABW4ItemID_t#0##Z) referenced in function "public: void __thiscall turtle::Barracks::swapItems(int,enum turtle::ItemID_t)" (?swapItems#Barracks#turtle##QAEXHW4ItemID_t#2##Z)
Thank you