C++ :: Create A Thread To A Class Function
Jan 25, 2014
I'm trying to create a thread to a class function, but it doesnt work for me...
The function : void Server::RecMsg(SOCKET &socket)
the call : std::thread GetMessages(&Server::RecMsg, ClientSocket);
I get the error : "Error1error C2064: term does not evaluate to a function taking 1 arguments"
View 1 Replies
ADVERTISEMENT
Apr 20, 2014
I have a header file with a bunch of functions. I want to create a thread using the <threads> package and am using
void myclass::functionX() {
}
void myclass::function() {
std::thread tr(myclass::functionX);
}
I am getting the error "no instance of std::thread::thread matches the argument list argument types are (void());
View 1 Replies
View Related
Dec 23, 2012
How can I implement the paradigm demonstrated by the code below to run on WinXP?
I want to fork a process or create a thread that shares global variables with the parent process/thread.
The child process/thread monitors the progress of the parent process/thread.
I cannot find documentation for a fork function per se, a Unix term. It might be called something different for WinXP.
I would be happy to use threads instead. But I'm rusty even with Unix application threads; and I know nothing of WinXP application threads.
So any turnkey implementation that demonstrates the simplest use of process or thread functions for my purpose demonstrated below.
In either case, do "forked" processes and threads share global address space in WinXP, as they do in Unix?
I would prefer to avoid the overhead of IPC mechanisms. The "overhead" includes my own relearning curve.
The GUI screwed up my indentation. I would try to correct it. But the proper indentation appears when I edit the posting. I suppose I need to insert real tabs. Haven't figured out how (yet).
Not even real tabs work; and I cannot get the "paste as text" button to behave as I expect. What is the trick for posting indented text in this GUI?
#include "stdafx.h"
#include <stdlib.h>
#include <Windows.h>
long curCount;
int isRunning;
int _tmain(int argc, char* argv[]) {
curCount = 0;
isRunning = 1;
[code]....
View 4 Replies
View Related
Dec 20, 2014
I'm trying to write a program that opens a directory and for each file in directory,it creates a thread. Inside of the thread,it reads the numbers in file.(one number in one line)And then calculates the average of these numbers. I write something like this;
void *calculate(FILE *piece){
int a,k=0,s=0,ort;
while(!feof(ayri)) {
a=fgetc(ayri);
s=s+a;
[Code] ....
When I run the programme,i get lots of errors like 'segmentation error' and some stuff about pthread_create. And I don't think the 'calculate' function is right.I don't know the right way to read numbers line by line.
View 3 Replies
View Related
Mar 19, 2013
I searched the web for error: C3867... and the discussions where murky or obscure.
My code excerpt is:
#pragma once
#include <windows.h>
#include <stdlib.h>
#include <process.h>
void PutUpfrmIO(void *);
namespace WordParsor {
[Code] .....
I get the generic message:
error C3867: 'WordParsor::Form1::PutUpfrmIO': function call missing argument list; use '&WordParsor::Form1::PutUpfrmIO' to create a pointer to memberc:userskingc++wordparsorwordparsorForm1.h... and the suggestion fix generate another error.
One person suggested the gcroot<> object wrapper... but I do not know how to modify/declair the function or its argument type.
View 2 Replies
View Related
May 7, 2013
I am new to C++ programming and i have a small assignment.
How to implement a thread safe class to manage a queue of objects. Accessing the front of the queue should be a blocking operation when the queue is empty.
View 4 Replies
View Related
Jul 30, 2014
I have a class which I wrote and one of its object is "SerialPort" .NET class. In my MainWindow I created instance of my class called "SerialPortComm", then I send through some functions of mine, commands to the Serial Port, and I receive answers through "DataReceived" event.
But when I trying to use Dispatcher.BeginInvoke to write my data I have received (successfully), nothing shows on the RichTextBox which I'm trying to write to.
What can caused that, and How I can make it works?
SerialPortComm.cs
public partial class SerialPortComm : UserControl {
public SerialPort mySerialPort = new SerialPort();
public void Open_Port(string comNumber, int baudRate) {
mySerialPort.PortName = comNumber;
mySerialPort.BaudRate = baudRate;
[Code] ....
View 7 Replies
View Related
Nov 24, 2014
How to call a thread by a function pointer?
I get "error C2059: syntax error : '(' " on the indicated line.
Code:
#include <windows.h>#include <iostream>
using namespace std;
DWORD WINAPI Thread() {
cout << "ok" << endl;
return 0;
[Code] ....
View 9 Replies
View Related
May 13, 2014
I am trying to realize a simple code with thread and lambda function.
My goal is to swap 2 variable . I launch 2 thread,
The first:
Put his value in a shared variable and notify it .
wait until an event on a condition variable occur.
read from shared value .
The second wait until an event on a condition variable occur.
Wake up
read from shared value .
Put his value in a shared variable and notify it.
This is the code
thread t1([&p1]()->void{
m.lock();
nt++;
if(nt==1) {
//first thread
unique_lock<mutex> u1(m); ***
[Code] .....
Why it say error "abort() has been called " on the istr ***
View 2 Replies
View Related
Sep 17, 2013
CODE:
class Secure {
private:
int seconds;
bool isRUNNING;
public:
Secure(int seconds) {
[Code] .....
ERROR:
error C2276: '&' : illegal operation on bound member function expression
I read that due to explicit casting, threads cannot be created within a class. I'm trying to thread a scanning system to relieve stress on my main program/module, rather than having the scanner stunt their performance.
View 4 Replies
View Related
Oct 26, 2013
I have a struct called Array and I'm to create a function to create a dynamic array that's fill with randomly generated integers from 0 to 50 (inclusive) and a function to destroy the array for freeing its memory. Below the code that I have written so far.
Code:
* Struct */
typedef struct {int *pArray; //the dynamic array
int length; //the size of the dynamic array}Array;
/* Function to create a dynamic array */
Array *initializeArray (int length) {int i;
}
[code]....
View 7 Replies
View Related
Feb 20, 2015
My thought is that I would need to establish a variable for the class in the header and call the class within the .cpp file
//class A.h
B b;
Then in class A, to create the object and use a method from the object I would -
//class A.cpp
A::A(){
b();
}
int someAmethod(){
b.bmethod();
}
View 6 Replies
View Related
Sep 18, 2013
How can a member function in my derived class call the same function from its base class?
View 1 Replies
View Related
Oct 6, 2013
I've tried to program a Singleton class. But the problem is that I don't know how to access the g_pInstance() function. Because this is not working because the constructor and deconstructor is private:
Singleton::g_pInstance()
Code: #include <iostream>
using namespace std;
class Singleton
{
[Code]....
I'm not sure of how to access any object, function, variables in the class when you are using a Singleton. How do you access that?
I'm just asking because I want to know how to do that if I have to use a Singleton sometime when I'm programming.
View 5 Replies
View Related
Feb 9, 2013
I know that it's a class that contains data from another class I just do not know how to make them both work together.
View 1 Replies
View Related
Dec 24, 2014
I wanted to create a new class object and I want to name it from a string. Something like this:
string name = "Mike";
Customers name;
//to create a new object in customer class using the name string
Is there any way to do this?
View 11 Replies
View Related
Mar 14, 2013
I need to create a C Wrapper around a C++_Class and in between needs to be an Interface-Class. The Interface-Class is needed, cause there are more C++_Classes which are kinda equal.
Hierarchicaly it would somehow look like this:
=> XY-Process which is calling the CWrapper
==> CMeasureWrapper.c// <-- CWrapper
===> CMeasureWrapper.h// <-- CWrapper Header
====> IMeasurement.h// <-- Interface-Class
=====> CMeasure.cpp// <-- C++_Class
======> CMeasure.h// <-- C++_Class-Header
My Output after compiling.(files will follow)
// CMeasureWrapper.c | CWrapper
#include "CMeasureWrapper.h"
uint32_t gu32_objectHandle;
uint32_t gu32_measureType;
int32_t addNewMeasureObject(uint32_t u32_measureObjType)
{
int32_t t_status = 0;
[Code]...
It's the first time i'll try to build an CWrapper or even a wrapper. So maybe the Project-Properties need to fit as well.
The project itself is called "Platform" with following settings in:
C/C++ -> Advanced -> Compile As -> "Compile as C++ Code (/TP)"
This property on the CMeasureWrapper.c is switched to:
C/C++ -> Advanced -> Compile As -> "Compile as C Code (/TC)" but only on this file!
I'm not sure if it's necessary, the file is of .c type, so I wasn't sure.
what I am doin wrong? Not just depending on the error output, I mean on the whole project. Is there anything else which will not work with such a combination of CWrapper, Interface and C++_Classes? If there are any questions, just throw them at me
View 2 Replies
View Related
Sep 4, 2013
I'm trying to learn as much C++ as I can. I was writing a program that mixes linked lists and classes. There is the class "Obj" which only holds an integer called 'data' and the classic "struct node" structure for linked list, but this time the "node" structure will hold an instance of "Obj" Class and the next* pointer.
#include <iostream>
using namespace std;
class Obj {
private:
int data;
public:
[code]....
View 2 Replies
View Related
Oct 13, 2013
I am working on a project that requires me to create objects from a abstract class that has 2 child classes (that need to be derived). Any examples on how to do this? I looked online and the examples were pretty vague. the main error that I am getting is when I make a temp object with & in front of it (such as Employee &genericEmp) it throws a must be initialized error.
View 6 Replies
View Related
Nov 3, 2013
regarding dynamic vector.
Shape2DLink.cpp
void Shape2DLink::InputSensor()
{
string shape,type;
[Code]....
So i'm actually using polyphormism for calculating the area of the cross and other shapes. so how do I actually make use of dynamically create an object this way?
do I create them in my Shape2DLink or in my individual child classes?
View 9 Replies
View Related
Dec 4, 2014
I am creating a program that allows a user to create multiple 'sequences' and multiple 'filters' and then apply a filter to a sequence.
Each sequence and filter is an array of values.
How do I go about allowing the user to create a 'new' sequence and then store the location so I can access it again later? Once they have created a new sequence they can go on to create another sequence and ten maybe a filter and then another sequence etc etc .. and then they can select sequence 1 and edit the values if they so wish.
They would be asked how many sample values for the sequence, and then I would create a sequence with that many values and an id (1,2,3,4...). They could then enter this id to view/edit the sequence.
The entering/editing values part I am fine with. I just don't know how to allow them to create multiple new instances of a class without using an array so something like..
sequenceClassName somearray[10];
int i;
*create a new array*
somearray[i].create_class(how_many_samples)
i++ //so next sequence they create is 2,3,4.. etc
- this then calls the member function that creates an array using 'sample_values = new float[how_many_samples]' and the user can input their data and edit it whenever by entering the id which will correspond to the somearray[i].
However that approach only allows them to enter a maximum of 11 sequences. It all depends on how big I make that initial array and it just seems like the wrong way to do it.
( how to interact with them, just how to create multiple classes and recall them later to access the data!)
View 2 Replies
View Related
Jul 8, 2014
Code:
class A {
public:
template<class T>
ObjectsBase* createObject(T* objType, Ogre::String name, Ogre::Vector3 position);
};
template<class T>
ObjectBase* A::createObject(T* objType, Ogre::String name, Ogre::Vector3 position);
My goal is to create any ObjectBase* derived object and return it to class A....
View 6 Replies
View Related
Mar 24, 2013
Create a class representing project activities. In this class include all the required data members and member functions. Each activity should have a record of activity duration, calculated early start, early finish, late start, late finish, free float, and total float. Each activity may or may not maintain a list of its successors and predecessors. Provide your design in UML and implement it in C++ using an interface head file and an implementation source file. I do not understand classes or UML designs.
View 2 Replies
View Related
Apr 27, 2014
I am new to C++. I am trying to create 5 instance object of class Test. I wonder if these two codes are the same.
Test testArray[5];
//which one is the correct way or what is the correct way?
for(i=0;i<5;i++)
{
Test testArray;
}
View 2 Replies
View Related
Aug 25, 2013
I'm new in object oriented programming. I need creating a global object/instance of a class, that can be used by any function.
View 19 Replies
View Related
Mar 13, 2014
I am trying to create two classes: a Date class and a Time class. The Date class has to have three private data members: day, month and year. The Time class should have two private data members:hour and minute. Each class should have two member functions: a constructor and display. I am lost and my code won't run ....
class Date {
private:
int month, day, year;
public:
Date(int m, int d, int y){
month = m;
day = d;
year = y;
[code]....
View 2 Replies
View Related