C/C++ :: Threading In Classes Instead Of Main?

Nov 1, 2013

I want to make a thread outside an int main() method; and this code below gives an error of (paraphrasing) 'no constructor found for thread for type void()'

#include <thread>;
class Board(){  
//Lines Later  

[Code]....

Is there any way to accomplish threading outside the main and in a class?

View 1 Replies


ADVERTISEMENT

C++ :: Defining Classes And Using Them Inside Void Main Function

May 18, 2013

This is a program I developed in which we had to define a class named BOOK with the data members and member functions as shown in the program..We have to:

(i) Make the user enter the values in the array BOOK.
(ii) Display the details that the user entered.
(iii) Search for a book from the array upon its Bno and display its details.
(iv) Search for a book from the array upon its Bname and display its details.

PROGRAM:

#include<iostream.h>
#include<conio.h>
#include<stdio.h>
#include<string.h>
class BOOK {
private:
int Bno;
char Bname[20];

[Code] .....

But while running it the compiler gives the errors as:

Line 43 to 48: Illegal character '' (0x5c)
Line 69: Undefined symbol 'Display'
Line 88: 'BOOK::Bno' is not accessible.
Line 89:'BOOK::Bname' is not accessible.
Line 90:'BOOK::Author' is not accesible.
Line 91:'BOOK::Price' is not accesible.
Line 108:'BOOK::Bno' is not accessible.
Line 109:'BOOK::Bname' is not accessible.
Line 110:'BOOK::Author' is not accesible.
Line 111:'BOOK::Price' is not accesible.
from 43 to 48..the line feed was also used at many other places but there it was not given as an error so why here?
Line 69: I defined the Display() function outside the class since it contained control structures, so what's the error then?

About the lines the rest of the error( the "not accessible" ones) I know these data members are not accessible because they are in private visibility mode. But then how to make them accessible? (Without putting them in public because it was a part of the question to create the data members in private).

View 1 Replies View Related

C :: Threading With OpenMP

Apr 10, 2013

I wrote code that finds the number of prime numbers in a range entered by the user. Now I'm attempting to make it run in parallel with the number of threads I assign it to have. I'm using blocking technique, so I'm assigning, in this scenario, 4 threads - 1/4 of the numbers in the range to the first array, and the next 1/4 of the numbers in the range to the next array and so on. Then I want to execute the prime number counting code in parallel. I'm using openMP to do this. I'm having difficulty setting it all up properly. I have a little experience with pthreads but little with openMP and am struggling in how this should be done.

Code:

#include <stdio.h>
#include <stdlib.h>
#include <omp.h>

[Code]....

View 2 Replies View Related

C++ :: Threading Over The Network With Pthread Or TBB?

Jun 13, 2013

I'm wondering if there is a library for C++ that supports threading over the network, maybe with a threading pool and a specific protocol; or if there is just a de-facto protocol for doing threading over the network.

View 10 Replies View Related

C/C++ :: Threading - How To Pass By Reference

May 13, 2014

I've written some code that I am currently threading but I am unsure how to pass by reference, or rather why my pass by reference is failing.

I am passing an array of floats by reference, this works fine when not threaded but I am given the error that float*&field does not match std::reference_wrapper<float*>.

Anyways. Here's the code.

The method:

diffuse(int b, float*& field, float*& pField, float diffFactor, float dt, int iteration)

The thread:

std::thread diffuseThread(diffuse, 1, std::ref(u), std::ref(prevU), visc, dt, iteration);

View 14 Replies View Related

C/C++ :: Threading / How To Invoke It Properly

Jun 12, 2012

I'm using MS' optimizing compiler CL 13.10 (one from VCToolkit 2003) along with WinAPI threading functions and is being compiled as a C console program.

I was wondering how to implement threading in a production setting? I've seen and tried various examples, but they all show basically the same thing - startup in main, run their function, clean up, and then the program exits.

I don't know the proper terminology, but I was looking for two maybe three functions to run simultaneously with a loop in main. I tried a small test program and was wondering if it's setup correctly.

A structure is used as the argument for each function.

int running = 1; // global variable  
DWORD WINAPI function_1(LPVOID);
DWORD WINAPI function_2(LPVOID);   
main() {  
   HANDLE hndThreads[2];
   DWORD threadIDs[2];

[code].....

Right now, function_2 is just a copy of function_1's definition. Everything *appears* to do what I want, but is it setup correctly?

View 2 Replies View Related

C :: Read Text File From Memory Card Using Threading

Mar 25, 2013

I need do read a text file from memory card using threading.

I am able to do it with out using thread but because of some limitations, i have to do it with threading only.

Here is the code to read file from memory card with out thread:

Code: ##########################################
#include <stdio.h>
#include <stdlib.h>
#include <XMC4500.h> /* SFR declarations of the selected device */
#include <DAVE3.h> /* Declarations from DAVE3 Code
#include <stdio.h>
#include <string.h>
#include <stdbool.h>

[Code]...

View 4 Replies View Related

C++ :: Recursive Directory Scan - Can Use Multi-threading For Speed?

May 11, 2014

In our Qt application, we have to load several files on application start-up starting from a root directory.

We are recursively scanning the directories and loading the files.

The total time it takes is about 12 seconds. Can we reduce this time if we use multi-threading?

I have heard that multi-threading does not work everywhere and it increases code complexity and debugging issues.

Would multi-threading solve the above problem? We want it to be platform independent (Mac, Linux, Windows).

View 9 Replies View Related

C++ :: Boost Threading - Cannot Access Private Member Declared In Class

Feb 25, 2013

When I put boost::thread Thread; in my struct I get the error error C2248: 'boost::thread::thread' : cannot access private member declared in class 'boost::thread'

The whole struct is

struct Player {
bool key[256];
char nameString[64];
bool lMouseButton;
bool rMouseButton;
double mouseX;
double mouseY;

[Code] ....

View 1 Replies View Related

C++ :: Why Windows Multi-threading Data Fetch IOPS Too Fast

Feb 10, 2012

I have a SSD and I am trying to use it to simulate my program I/O performance, however, IOPS calculated from my program is much much faster than IOMeter.

My SSD is PLEXTOR PX-128M3S, by IOMeter, its max 512B random read IOPS is around 94k (queue depth is 32). However my program (32 windows threads) can reach around 500k 512B IOPS, around 5 times of IOMeter!!! I did data validation but didn't find any error in data fetching. It's because my data fetching in order?

I paste my code belwo (it mainly fetch 512B from file and release it; I did use 4bytes (an int) to validate program logic and didn't find problem).

#include <stdio.h>
#include <Windows.h>
/*
** Purpose: Verify file random read IOPS in comparison with IOMeter
**/

//Global variables
long completeIOs = 0;
long completeBytes = 0;
int threadCount = 32;
unsigned long long length = 1073741824; //4G test file

[Code] ....

View 1 Replies View Related

C++ :: Array Of Classes With Classes Inside

Oct 5, 2013

I have an array of (Student)classes created in Manager.h, which contains a new instance of class Name (name),(in Student.h)How would I go about accessing the SetFirstName method in Name.cpp if I was in a class Manager.cpp? I have tried using Students[i].name.SetFirstName("name");

// In Manager.h
#include"Student.h"
class Manager
{

[Code]....

View 2 Replies View Related

C :: Difference Between Two Int Main Functions

Feb 6, 2014

I just wanted to know what's the difference between these two types of main functions:

Code: int main (int argc, char** argv){ ... }

Code: int main (int argc, char* argv[]){ ... }

View 4 Replies View Related

C :: How To Print The String In Main

May 23, 2013

if you have something like this how can you print the string in main??

Code:

/#include <stdio.h>
#include <stdlib.h>
void myf(char *p)
{
p="balls";
}
int main()
{

[Code]...

View 2 Replies View Related

C :: Passing Arguments To Main

Feb 10, 2015

I have a 1wire program from maxim running in visual studio. There is this argument in the main function that requires the com port to be specified the command line. If I do pass it as "COM1" the program works as expected.

I don't want to depend on having to pass "COM1" in the command line and into main. I've tried creating a string for COM1 and passing it right into the if function but it doesn't work.

Code:
int main(int argc, char **argv) {
int len, addr, page, answer, i;
int done = FALSE;
SMALLINT bank = 1;
uchar data[552];

[Code] .....

View 1 Replies View Related

C++ :: Returning Values To Main

Nov 5, 2014

I am working on this program below. The problem I am having is trying to return totalDays to the main. In the numOfDays() function there is a for loop that adds the totalDays (totalDays = totalDays + days). I have just been getting errors in returning the correct amount of totalDays to the main from the numOfDays function.

#include <iostream>
using namespace std;
int numOfEmployees();
int numOfDays(int);
int main() {
int totalDays = 0;

[Code] ....

View 2 Replies View Related

C++ :: Pass From Function To Main

Apr 24, 2014

Why the value does not return; Here is code

#include <iostream>
#include <string>
#include <ctime> // to use the time function
#include <cstdlib>
using namespace std;
int getUserChoose (int);

[Code] ....

here is the output

Welcome to the program of Rock, Paper, Scissors
The computer is ready to play the game
Are you ready to play the game
Y for yes and N for no
Y
R = Rock; P = Paper; S = Scissors
R
You have choose Rock
1TN
1RM
0U
0C

View 5 Replies View Related

C++ :: Best Way To Split Main Program?

Apr 26, 2013

I need to split my main() function into two separate functions.Where would the best place be to split it up?

* Read a text file whose name is given on the command line, and for each word:
* if it is an integer, insert it into an array in sorted order
* if it is not an integer, insert it into an array of words.

* Notes: converted to use C++ strings, because C strings are messier.
* Need to grow arrays, need to insert in sorted order.
* Growing arrays might be done the way we grew a C string:

* bigger = new <type> [size+1]
* for(i=0; i<size; i++) {
* bigger[i] = oldarray[i];

[code]....

View 1 Replies View Related

C++ :: How To Go Back In The Main Menu

Apr 9, 2014

I'm new here! I just wanted to ask, how can I go back to Main menu using this code that I have made (I know it's not yet finish I'm using Visual Studio c++ 2010! I there are any errors in my codes

Project: Computer Shop System

#include <iostream>
#include <string>
using namespace std;
int pcnum[5],x; //choice pc
int pc;
int i; //name
int y; //hours

[Code]...

View 1 Replies View Related

C/C++ :: Main Menu Keeps On Appearing

Apr 5, 2014

#include "Header.h"
#include <iostream>
#include <string>
#include <iomanip>
#include <cmath>
using namespace std;
int option = 0;
char add;

[Code] ....

View 1 Replies View Related

C/C++ :: Is It Necessary Function Main Should Return Int?

Jan 24, 2013

If so what is the reason, and the returning int value indicates wat?

View 4 Replies View Related

C++ :: How Do Two Classes Interact With Each Other

Aug 26, 2013

I want to know that how objects of two different classes interact with each other???

View 1 Replies View Related

C++ :: How To Know If Classes In Program Are Being Used

Aug 13, 2014

In this program the intention is to create a menu driven program for a pizza restaurant. I have to use a class called Pizza and have to include at least three public functions; one is called SetSize, another one is called Display, and the last one is called ComputePrice. A small pizza is worth $10, a medium is $14, and a large is $17. Each topping is worth 2 dollars. I know that the program runs correctly, but I have doubts over the classes and function actually being utilized correctly or at all.

Program:

#include <iostream>
#include <iomanip>
#include <cmath>
using namespace std;
class Pizza {
private:

int size;
int style;

[Code] .....

View 8 Replies View Related

C++ :: Using Multiset With Classes?

Oct 23, 2013

I'm trying to use multiset with a user defined class "edge". I'm trying to use the multiset as a priority queue, and I've created a "less<edge>" via operator<() overloading.

For some reason, I cannot insert edges into the multiset.

I understand that I might also have to create an "allocator". I got some ideas for creating it at [URL], but still don't know how to define size_type and difference_type.

Attached is my skeleton code, running on Windows 7 (32-bit), under Netbeans IDE, using Cygwin g++ 4.7.3.

How can I get this to work? What is important is that I get a priority queue working with my edges, prioritized by the weight.

#include <iostream>
#include <set> // for multiset
using namespace std; // assume std libraries (i.e. std::XXX)
class edge { // node, weight pair
public:

[Code].....

View 3 Replies View Related

C++ :: Derived Classes From DLL

May 5, 2013

I've created a base DLL for all my future DLL's, a way of getting version numbers and such and that compiles fine, but I can't add it into a class for a new DLL. All the headers do have an appropriate cpp to define the function declarations (and they compile fine).

All for the base DLL I have:

LibVer.h
Version.cpp
Function.cpp

LibVer.h

#pragma once
#include <vector>
#define DLLEXPORT 1
#define DLLIMPORT 2
#define DLL DLLIMPORT

[Code] .....

View 6 Replies View Related

C# :: Can Use Variables From Other Classes

Feb 23, 2014

im creating an address book. One address book contains a ListBox, New User button, Edit User and Remove User button. The first form is suppose to allow you to view the users you've created on the ListBox and you can decide whether you want to remove it, create a new one or simply edit the user. Now The second form simply contains labels and textbox along with a save button. I'm having a bit of issue figuring out the ListBox. I want to be able to create a user and have the user be posted on the ListBox. I read that i must instantiate listbox then simply add it. Now on my form2 i have a for loop that loops through an Array of String were all the users will be created on. How can i call that array of string on to the form1?

Form 1:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

[code].....

EDIT:I just figured out that to call a variable from one form to another you simply instantiate the form then simply call it. PS. must be set to public:

ListBox1 createUser = new ListBox1();
createUser.userString[0];

why doesnt it show the windows when i run without debugging?

View 1 Replies View Related

C/C++ :: Get Volume Of A Box Using Classes

Feb 22, 2015

n the requirements it says this;

-create a get and set for height, width, length.
-A default parameterized constructor = 1
-A method to resize the box
-A method to get the volume of the box
-A method to convert the object to a string

My Questions:

The 3 parts I am confused by are the default parameter constructor, the re-size the box and the method to convert to string. For the default parameter part I figured making length, width and height = to 1 would work, but I'm pretty sure thats not what I'm supposed to do.

This is the main file

#include "box_class.h"
#include <iostream>
using namespace std;
int main() {
double length;
double width;
double height;
double volume;

[Code] ......

View 1 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved