FifoQueue does not name a type - omnet++

im new to OMNET++/INET and im trying to use the FifoQueue from the INET library. I included the header files but i can't use the class itself and says that FifoQueue does not name a type. I don't know what am i doing wrong.
#ifndef SERVER_H_
#define SERVER_H_
#include <stdio.h>
#include <string.h>
#include <omnetpp.h>
#include "inet/common/INETDefs.h"
#include "inet/common/queue/FifoQueue.h"
using namespace omnetpp;
using namespace std;
class Server : public cSimpleModule
{
private:
cMessage *refillCapacity;
cMessage *checkQueue;
double checkTimer = 0.001;
double refillTimer = 1.0;
FifoQueue *Searchqueue;// IPassiveQueue a;
protected:
virtual void initialize() override;
virtual void handleMessage(cMessage *msg) override;
};
Define_Module(Server);
#endif /* SERVER_H_ */
Can anyone help me?

First of all remove the line
Define_Module(Server);
from the header file. This line is required but in source file.
FifoQueue is the simple module. So one can use it by placing it in own module defined in NED. An example of using it may be found in INET: src\inet\networklayer\diffserv\AFxyQueue.ned

Related

"GetForegroundWindow: identifier not found" in visual studio 2015

I am developing a windows app in visual studio 2015 using C++. I need GetForegroundWindow() and GetWindowText() to return the app that is currently focusing on. However, it says GetForegroundWindow() and GetWindowText() are undefined even I've included "windows.h". I tried go to the definition of GetForegroundWindow(), it led me to "WinUser.h", so I included "WinUser.h" as well. But it still could not help. Here are my code:
#include "MainPage.xaml.h"
#include <windows.h>
#include <WinUser.h>
#include <winapifamily.h>
#include <string>
#include <stdio.h>
#include <iostream>
using namespace App1;
using namespace Platform;
using namespace Windows::Foundation;
using namespace Windows::Foundation::Collections;
using namespace Windows::UI::Xaml;
using namespace Windows::UI::Xaml::Controls;
using namespace Windows::UI::Xaml::Controls::Primitives;
using namespace Windows::UI::Xaml::Data;
using namespace Windows::UI::Xaml::Input;
using namespace Windows::UI::Xaml::Media;
using namespace Windows::UI::Xaml::Navigation;
using std::cout;
using std::endl;
MainPage::MainPage()
{
InitializeComponent();
}
HWND currenthwnd, hwnd = NULL;
char wnd_title[1024];
void App1::MainPage::Focus_app_Click(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e)
{
currenthwnd = GetForegroundWindow();
GetWindowText(hwnd, wnd_title, sizeof(wnd_title));
cout << wnd_title << endl;
}
Any ideas? Thanks in advance!
GetForegroundWindowand GetWindowText in the WinUser.h are declared inside #if WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP) macro block. So you could use them only for windows desktop applications.

How to wrap a c++ class with an opencv object with c++/cli

I would like to wrap a complex c++ class which used opencv object with c++/cli for using in c# and vb. I'm using Visual Studio 2015. I'm using the x64 versions of of the OpenCV library and compiling also to x64.
Following is the header.h file of a small test class, just as an example:
#pragma once
#include <vector>
#include "opencv2/opencv.hpp"
using namespace std;
class compC
{
public:
compC(int * pInt, int arrSize);
int sumArray();
private:
vector<int> vec;
cv::Mat img;
};
This is going to be compiled as a win32-application to a .lib file without any problems.
The example wrapper class (wrapper.h) would look like:
#pragma once
#include "../ConsoleApplication1/header.h"
#include "../ConsoleApplication1/body.cpp"
using namespace System;
namespace WrapperLibrary {
public ref class WrapperClass
{
public:
WrapperClass(int * pInt, int arraySize);
int getSum();
private:
compC * pcC;
int sum;
};
}
The second class would be compiled as a dll with /clr (as c++/cli project).
First I got an error that opencv.hpp could not be find and had to add the include directory of opencv in to the wrapper project. But I cannot compile it and get a lot of errors, mainly pointing to linking problems "unresolved external problems ..." in connection with the opencv-mat object.
If I remove the lines
#include "opencv2/opencv.hpp"
and
cv::Mat img;
in the test class (header.h) all will be fine.
What did I made wrong? How can I wrap those c++ class with c++/cli?

Error while trying to use strings while working with windows application forms

When creating a new class while working in a project that is based around windows application forms. I have a problem where string becomes unusable. I get errors the say things like
"a member of a managed class cannot be of a non-managed class type"
"IntelliSense: a function type involving a generic parameter cannot have an ellipsis parameter"
"IntelliSense: linkage specification is incompatible with previous "bsearch_s"(declared at line 426)"
Person.h
#pragma once
#include <string>
using namespace std;
ref class Person
{
public:
Person(void);
string name;
};
Person.cpp
#include "stdafx.h"
#include "Person.h"
#include <string>
using namespace std;
Person::Person(void)
{
name = "Bob";
}
If someone has a solution to this or a work around that isn't creating my own string class I would love to hear it as this has been bothering me for days.
String header in CLI C++ is already included in the System namespace.
String works as a pointer. Using the cap ^ handler
//This works:
#include "stdafx.h"
using namespace System;
void function()
{
String^ simpleStr = "Bob";
}

Visual C++ failure to include

I have two mutually dependent header files: BarP.h and addNewProductForm.h, built using Microsoft CLR components, which look something like this (they are way too long to include intact):
BarP.h:
#pragma once
#include "addNewProductForm.h"
#include "editBarOptionsForm.h"
#include "editDecayParamsForm.h"
#include "editExistingItemForm.h"
#include <math.h>
#include <string>
#include <iostream>
#include <fstream>
#include <msclr\marshal.h>
namespace BarPricer3 {
using namespace std;
using namespace System;
using namespace System::ComponentModel;
using namespace System::Collections;
using namespace System::Windows::Forms;
using namespace System::Data;
using namespace System::Drawing;
using namespace msclr::interop;
ref struct productDat{...};
productDat^ createProduct(String^ name,double firstPrice,double lastPrice,double lastDemand){...};
public ref class BarP{
...
private: System::Void createNewProductForm(...){
BarPricer3::addNewProductForm^ newProductForm = gcnew addNewProductForm;
newProductForm->ShowDialog(this);
}
}
addNewProductForm.h
#pragma once
#include "BarP.h"
#include <fstream>
namespace BarPricer3 {
using namespace std;
using namespace System;
using namespace System::ComponentModel;
using namespace System::Collections;
using namespace System::Windows::Forms;
using namespace System::Data;
using namespace System::Drawing;
public ref class addNewProductForm{
...
private: System::Void createNewProduct(...){
productDat^ theNewP = createProduct(this->name->Text,Convert::ToDouble(this->firstPrice->Text),Convert::ToDouble(this->lastPrice->Text),Convert::ToDouble(this->lastDemand->Text));
...
}
}
When I try to compile, I get the following errors:
Error 8 error C2039: 'addNewProductForm' : is not a member of 'BarPricer3' d:...\BarP.h 690 (line 32 in my code)
Error 15 error C2065: 'productDat' : undeclared identifier d:...\addNewProductForm.h 181 (line 19 in my code)
Can I get any advice about what's happening here?
You have a circular inclusion in the header files, and that, combined with the #pragma once directive, is what yields the error. You need to remove one of the includes (or both) and replace them with a forward declaration (might want to google this).
You'll probably need to separate the implementations to a different file, because you use the types inside the headers.
Your problem is that addNewProductForm.h uses productDat which is defined in BarP.h, and that BarP.h uses addNewProductForm which is defined in addNewProductForm.h. (These are the classes that will need to be forward-declared).

"seekg identifier not found"

I have a program called main:
#include<iostream>
#include<fstream>
using namespace std;
#include"other.h"
int main()
{
//do stuff
}
and then other.h:
char* load_data(int begin_point,int num_characters)
{
seekg(begin_point);
char* return_val=new char[num_characters+1];
mapdata.getline(return_val,num_characters);
return return_val;
}
and I get the error:
'seekg': identifier not found
why do I get this error and how do I fix it?
seekg is a method from the fstream (declared in istream) class.
You haven't instantiated any.
Take this as an example
ifstream is;
is.open ("test.txt", ios::binary );
// get length of file:
is.seekg (0, ios::end);
source: http://www.cplusplus.com/reference/iostream/istream/seekg/
So, you should
char* load_data(int begin_point,int num_characters)
{
ifstream is;
is("yourfile.txt") //file is now open for reading.
seekg(begin_point);
char* return_val=new char[num_characters+1];
mapdata.getline(return_val,num_characters);
return return_val;
}
Take into account what ParoXon commented in your question.
You should create a file other.cpp containing function's load_data implementation.
File other.h should contain function's load_data declaration. In that file (other.h) you should include all files neccesary for functions declared there to work. And dont forget to protect yourself against multiple includes !
File other.h
#ifndef __OTHER_H__
#define __OTHER_H__
#include <iostream>
#include <fstream>
char* load_data(int,int);//no implementation
#endif
File other.cpp
#include "other.h" //assumes other.h and other.cpp in same directory
char* load_data(int begin,int amount){
//load_data implementation
}

Resources