C++ :: How To Pass Same Instance Of Object In Two Functions

Feb 25, 2014

I need to send same instance of object of a class in two function (Main function and thread function). The class is something like this:

//The class need to have constructor.
Class ABC {
public:
DWORD *IdG;
ABC(int number) {
IdG = new DWORD[number];
}
}obj(32);

The obj(32) is called in following two function. Function F1 is called using thread in main function.

void F1() {
obj.test;
}
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd) {
obj.test1;
_beginthread(F1,0,(void*)number);
}

The code works well when the object of class ABC is created as shown above. My problem is the value that is passed in the object ('32') is to be read from the file.

If I read the file and create object separately in Main function and function 'F1' then , function 'F1' is not executed.

How to create same instance of object for Main function and function 'F1' with value passed in the object taken from the file.

View 1 Replies


ADVERTISEMENT

C# :: Method Is Overwriting Both Instance Of Object And Original Object

Jul 3, 2014

I have a method to take a Tile object and make an instances of it based on some data from the original object. Than it is suppose to manipulate the a specific instance and save the results. The first loop through it works but it changes all instance as well as the base.

public static int recurse(int count, Tile[,] b,Huristic h,int check) {
if (check==1) {
boardState.Add(B)/>;
return check;
} if (check == 0)

[Code] .....

View 6 Replies View Related

C# :: Constructor Object Reference Not To Set Instance Of Object

Mar 28, 2014

I am trying to use web api in order to return custom json response keys. For this i have return a custom class to return json response

Custom Class:

using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;

[Code].....

View 2 Replies View Related

C Sharp :: Object Reference Not Set To Instance Of Object?

May 4, 2013

I have a combobox with Items 1024
2048
4096
8192

String cach = form.comboCache.SelectedItem.ToString();

I am using the above code to retrive an item selected by user,But this line is giving an exception "Null Reference Exception, Object reference not set to an instance of an object"

View 1 Replies View Related

C# :: Object Reference Not Set To Instance Of Object?

Mar 28, 2014

I am using session to pass object from controller to custom class in MVC Web API. here is my code, i am getting error at session.

public HttpResponseMessage Get()
{
var person = db.Persons.ToList();

[Code]....

View 1 Replies View Related

C# :: Getting Instance Object Is Null Compile

Dec 2, 2011

Code:

public class ColorGenetics
{
public static hk1Class jw;
public static linkedClass link;
}

[code]...

Code builds fine but compiler says I tried to use bject link w/o providing an instance. Class linkedClass has an instance of Class hk1Class set to var jw1.I had linkedClass useing the same var jw for the object instance. I changed it to jw1 thinking that would clear it up and it didn't.

View 2 Replies View Related

C++ :: Create 5 Instance Object Of Class Test?

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

C++ ::  How To Create Global Object / Instance Of A Class

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

C++ :: How To Store The Same Instance Of One Object In Multiple Vectors

Feb 4, 2015

If I have a class object and multiple vectors, how do I make sure I store the same instance of that object in both vectors? For instance:

Object object;
std::vector<Object> vectorOne;
std::vector<Object> vectorTwo;
vectorOne.push_back(object);
vectorTwo.push_back(object);

Are the objects in both vectors the same instance of the object? Like if I called vectorOne[0].setValue(somethingDifferent); would the value be changed for the object in both vectorOne and vectorTwo? If not, how do I make sure that I only have one instance of the object I'm trying to store in multiple vectors?

View 15 Replies View Related

C# :: Creating Instance Of A Class Given Its Assembly Object

Jan 15, 2015

Let's say I reference a dll in my project that has an abstract class in it:

public abstract class Module {
public string type;
public abstract string doSomething();
}

And then I have an Assembly object, loaded from a dll that is not referenced in project, but rather loaded during run-time, containing:

public class Tester : Module
{
public static string type = "Test";
public override void doSomething() {
//Stuff being done
return "hello";
}
}

How can I get the value of "type" in the class that is loaded during runtime? How do I use the "doSomething" method of it and get the returned object?

View 8 Replies View Related

C# :: Rain Application - Object Reference Not Set To Instance Of Obj

Mar 2, 2014

I'm trying to make a "Rain" application, by drawing some lines on the form, and then they must fall. So here is my start code:

public partial class Form1 : Form {
public Form1() {
InitializeComponent();
}
Random r = new Random();
Graphics paper;
Line line;

[Code] ....

So when I start debugging I get the "Object reference not set to an instance of an object." error. If I remove the comments lines at "timer1_Tick" this error doesn't appear of course. What can I do to escape from this because it follows me everywhere I go />. I tried to make with arrays, but same problem.

View 4 Replies View Related

C# :: Object Instance Not Retaining Field Values

Jun 13, 2014

I have this class:

class Excuse
{...
public string Description { get; set; }
public string Results { get; set; }
public DateTime LastUsed { get; set; }
public string ExcusePath { get; set; }
....}

[Code] ...

When I run it, I do get the messagebox popping up with the correct description, but then nothing happens. When I debug, I see the fields under the UpdateForm() method are set to null.

I'm guessing this happening because it is looking at the 'currentExcuse' that was declared in the form body. I thought however that redeclaring 'currentExcuse' in the method would overwrite this instance or am I wrong?

Do I need an array to make this work?

View 3 Replies View Related

C++ :: Trying To Pass Array Of Object

Apr 24, 2013

I am trying to pass an array of objects however i m finding some problems.

pieces.h

Code: class Cpiece{
public:
Cpiece* board[8][8];// array of objects
virtual char getcolor() =0;
virtual char setcolor(char colour)=0;

[Code] .....

View 10 Replies View Related

C/C++ :: Pass Value From Object To Array

Apr 16, 2014

I am trying to write a poker program. I created a class to create a deck of cards..and then shuffle the deck..Now I am trying to pass value from the deck to an array to deal a hand..so 5 cards to player1[] array.. I tried doing it directly such as.

for (int j = 0; j < 5; j++) {
getCard=deck[j].toString();
}

But I would get error such as [Error] no match for 'operator=' in 'player1[j] = deck[j].Card::toString()'

So then I tried using a pointer..

char *getCard;
getCard = new char;
for (int j = 0; j < 5; j++) {
getCard=deck[j].toString();
}

but I would get this error [Error] void value not ignored as it ought to be. So how can I pass a value from the object deck..to an array? or should I be doing it another way?..I tried to think of a way to do it via a function but really got hung up there..

here is full code

#include <stdlib.h>
#include <iostream>
#include <ctime>
#include <algorithm>
using namespace std;
const char* FaceString[13] = {"Ace", "2", "3", "4",
"5", "6", "7", "8",
"9", "10", "Jack", "Queen", "King"};

[Code] ....

View 11 Replies View Related

C :: How To Pass Arrays To Functions

Sep 23, 2014

I have read about it in my book and also on this website but i still have things uncleared....

View 11 Replies View Related

C :: Pass Variables Between Functions

Jun 29, 2014

I'm playing around with GTK+ 2.x and currently I have a button to call a function like so:

Code:
void selectmod(GtkWidget *downloadbutton, GtkComboBox *modlist, gchar *data){
gchar *mod = gtk_combo_box_get_active_text(modlist);
printf("
%s", mod);
}

How can I pass the *mod variable to another function?

View 9 Replies View Related

C++ :: Can't Pass To Functions With Pointer

May 25, 2013

I get a run time error saying something about memory locations when I run this program.How can I make this program work using pointers?

//this program converst miles to km
#include<iostream>
#include "std_lib_facilities.h"

[Code]....

View 1 Replies View Related

C++ :: Pass Object As A Pointer In Function

Apr 12, 2013

i need to pass myboard.board (board is in the class Cboard and it is an array of int) to a function in a class called piece however this is troubling . i need to pass it as pointer os that i could change its value here under is my code.

main.cpp Code: #include<iostream>
#include"board.h"
#include "pieces.h"

[Code].....

View 7 Replies View Related

C++ :: Pass Class Object By Reference

Jun 25, 2013

I am having trouble working with third party dll's, libs and header files. I am trying to call a function.here is the function that is suppose to be called.

bool COAuthSDK::GetRequestToken(CClientDetails &objClientDetails)

it has this info of what it needs :

Name IN/OUT Description
m_environment IN Optional. Possible values are SANDBOX (default) and LIVE.
m_strConsumerKey IN OAuth consumer key provided by E*TRADE
m_strConsumerSecret IN OAuth consumer secret provided by E*TRADE
m_strToken OUT Returned by the function if successful
m_strTokenSecret OUT Returned by the function if successful
m_strCallback IN Optional; default value is "oob"

here is the COAuthSDK header

#ifndef _OAUTHSDK_H_INCLUDED_
#define _OAUTHSDK_H_INCLUDED_
#include "ETCOMMONCommonDefs.h"
#include "ETCOMMONOAuthHelper.h"
using namespace std;

[code].....

when I try to build the function it says that its in the dll's so I know I have to call it.here is the link to the build site if needed URL....

View 1 Replies View Related

C++ :: Pass Class Object By Reference?

Mar 17, 2014

I'm trying to pass a class object by reference.

total = mathfunction(i);
}
double mathfunction(retirement& j)
{
double R = 0.00, m = 0.00, r = 0.00, t = 0.00, totaled = 0.00,
numerator = 0.00, denom = 0.00, temp = 0.00;

[Code]....

I only tried to pass by reference because I figured passing by value would be a larger pain in the neck.

View 1 Replies View Related

C++ :: How To Pass Arguments From Other Functions To Main

Sep 6, 2013

How to pass arguments from other functions to main. i want to write a program like nano well not exactly like nano editor. I have a function f_read(char* filename[]), and fopen() get filename[1] as file name and *filename[2] as "r" read mode and rest of the code will read from a file.

I want is this char filename[] to main(int argc , char argv[])

how can i do that??

View 4 Replies View Related

C/C++ :: How To Pass Structure Variables Between Functions

Jul 13, 2014

I have a project for class where I have to create a structure and get user input for 3 structure variable arrays of 10. I am trying to figure out how I can use the same function to fill my different section of variables.

My Structure is an employee file of ID number, name, hours, payrate, and then gross pay. I have to create a function for each input function. I am confused on how to pass the structure variable so that I do not have to write 3 functions for each input. I would like to be able to get all the info for the first structure variable and then recall the same 5 functions for the next before moving along. I hope that I have been able to make this clear. Here is my code:

#include<iostream>
#include<iomanip>
#include<cctype>
#include<string>
#include<cstring>
using namespace std;
struct PayPeeps_CL//Payroll Structure {

[Code] .....

View 14 Replies View Related

C++ :: How To Pass Structure Values Between Functions

Dec 29, 2012

Code:
struct NewPlayer {
int level;
int intelligence;
int damage;
};
int CharacterInfo(NewPlayer MageWizard, int Clevel,int Cint, int Cdam)

[Code] .....

View 1 Replies View Related

C# :: Determinate Type Of Object And Pass It Through Method

Sep 18, 2014

I got base class called Statistic and inherited classes from it : lsp, cpu, memory. Those methods inheriting some of methods from Statistic and implement also theirself methods. I prepared some new class called ExecuteRequest which is taking Statistic object in the constructor. What i want to achieve is after i put e.g LSP to this class i would like to determinate what specific object it is in this case LSP right? Then having that i would like to put this object to RunRequest method. How can i achieve that? See my code below:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace SOAP_testing {
public class ExecuteRequest

[Code] .....

View 14 Replies View Related

C :: Pass Values In Functions And Writing Them To A Txt File

Aug 23, 2013

This code is for fun, and have it doing a lot of what I want it to, just not all. I want random generated to write to a txt file. I tried to use an array but that failed. I wanted to use an array because i am only passing one value. Which makes sense since the random generated function is an int.

I made the fprintf as a comment but hopefully soon it will be able to send the values to the txt file. After that I will tackle the function.

Code:

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#define HIGH 49
#define LOW 1
int random_generated()

[Code]...

View 11 Replies View Related

C++ :: Unable To Pass Reference Of Object Ifstream To Constructor

Jan 30, 2013

I'm trying to pass an reference of the object ifstream to my constructor as such:

// myClass.cpp
int main(){
ifstream file;
myClass classobj = myClass(file);}

I am defining the constructor as follows, in myClass.cpp:

myClass::myClass(ifstream &file){
// do stuff
}

I get the error of "No overloaded function of myClass::myClass matches the specified type."

Also, when I build the program, it tells me "syntax error: identifier 'ifstream'"

Also, I made sure I included this:
#include <iostream>
#include <fstream>
#include <sstream>

What am I doing wrong? How can I pass an ifstream reference to my constructor?

View 3 Replies View Related







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