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.
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..
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.
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.
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"
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.
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
class A (abstract) class B : A class C { void add ( A(&*?) a ) std::vector<std::unique_ptr<A>> data; //unique_ptr<A> because A is abstract and therefore vector<A> isn't possible }
upper situation. What is the best way to pass add an object of class B to C?
with C::add(A* a){ vector.push_back( unique_ptr<A>(a) ); } and int main() { C c; c.add( new B() ); }
This works, but i don't think it's very nice, because you could delete the pointer in main. What happens then with the unique_ptr? I could probably make C::add( std::unique_ptr<A> u_p ); but maybe it can be avoided that the "user" (in main() ) has to create the unique_ptr itself.
The following code compiles and runs fine till it reaches line 16 and gets a sigsev violation which I'm not sure about as to why. I have no problem passing the object of type node** into the constructor of base and storing it into the double pointer node** copy;; but when I call the function void pass(node** temp) it crashes.
#include <iostream> class base; class node { private: node** data; public:
I would like to have 2 functions. (FYI, I haven't even tested these because I don't have a compiler on this PC, so don't know what they'll do. I'm also new to C++, self-teaching.)
My question is, I'm sure that oFile should be type object (of some sort), not int, but I'm not sure how to reference it correctly so that it passes from FileOpen to main to FileClose.
Code: #include <iostream> //I/O using namespace std; #include <fstream> //files using namespace ios; int FileOpen(string fileName) { ifstream oFile (fileName); //attempt to open file
I'm trying to figure out how I can create a vertex array object at offset of a vertex buffer object.I've created the buffer object. I'd like the "texs" idnex data to start at the texture coordinate content of the vertex_t structure.
Type definitions:
struct vertex_t { vector3d_t position; float s; // Texture coordinate s float t; // Texture coordinate t };
Code so far:
// How do I make this start at a certain spot of the VBO?! glVertexAttribPointer(texs, 2, GL_FLOAT, GL_FALSE, sizeof(vector3d_t), nullptr; //...
I'm trying to pass an array from one function to another without resorting to pointers and I have to use Pass by Reference. I can't seem to figure it out. I've been looking at many examples and just don't get it.
the function createAbc makes an array populated with the Alphabet. I need to pass that into my display function so that i can work with the array there. I don't know how to pass it in there... :(
I want to pass an array to a constructor, but only the first value is passed--the rest looks like garbage. Here's a simplified version of what I'm working on:
#include <iostream> class board { public: int state[64]; board(int arr[])
[Code] ....
Why this doesn't work and how to properly pass an array? Notes: I don't want to copy the array. Also, I'm using MSVC++ 2010 Express.
I've been given an assignment with the below questions.
1. What is the difference between pass by reference & pass by pointers?
2. What is the use of the initialization list in the constructor?
3. What is meant by a reference & its advantage?
4. Class has a reference, pointer and a const. Is it possible to write the copy constructor & assignment operator overloading funciton? how? ( Since reference is there, I'm not sure on how to write for it)
5. Example for a variable decleration and definition? (I know for function but for variable don kw how)
6. static and const static what is the difference??
How would I pass let say 2 array pointers to a function X , allocate memory for them in X , fill them with values and get them back in my main function without creating a structure.
example:
Code:
void X(int *a, int*b){ a= malloc ... b = malloc ... // fill a and b return them back to the main function } void main(){
I have been working on this all day, and its due in like an hour and a half. I have done everything the program wants except the last part. Here is the assignment:
Write a program that inputs 10 integers from the console into an array, and removes the duplicate array elements and prints the array. You may assume that all the integers are between 0 and 100, Write at least 1 function in addition to the main function, and pass an array into that function as a parameter. e.g.
Please enter your 10 numbers: 1 2 3 4 5 6 7 8 9 10 The array contains: 1 2 3 4 5 6 7 8 9 10
Please enter your 10 numbers: 1 1 3 3 3 6 7 8 9 9 The array contains: 1 3 6 7 8 9
Please enter your 10 numbers: 1 1 1 1 1 1 1 1 1 1 The array contains: 1
The bolded part is what I cant get to work. I have tried this and it keeps telling me I have not identified the items when I have.
Here is my code:
#include "stdafx.h" #include <iostream> using namespace std;
Now when I want to access that array, I have the following:
ptrSomeStruct->structArray[someIndex];
But now I want to pass structArray to this function by reference so that it can adjust the array as needed and I can continue to use the array back in my caller function:
I am attempting to write a program " that has a function that is passed an array of int and its size, and with that it prints out only the numbers that are above average. "
I have included my code so far, but I am only getting one value as output, and that value seems to be completely off. I keep trying, but I am really stuck.
#include <iostream> using namespace std; int average(int values[],int size); int main(){ int size; int values[] = {1,2,3,4,5,6};
[Code] ....
Added the floats in the average() function. But there is still a value problem.
How to pass my array to the function and return it as a sorted vector. I'm kind of lost with the functions part.
Problem: Write a program that performs a sorting routine as discussed in class. Create an array of 10 integers (e.g., 63, 42, 27, 111, 55, 14, 66, 9, 75, 87). Pass this array to a separate function that sorts the integers and returns a vector containing the sorted integers. Use either the SELECTIONSORT algorithm or the INSERTIONSORT.
You might notice that the above code doesn't compile, this is the error:
cannot convert parameter 2 from 'BYTE [2][4]' to 'BYTE *' 1> Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
Even after some search I couldn't really find an answer to my problem, how do I pass the const BYTE array which I declared above in the function as a parameter (or what structure do I need to set for the function as a parameter)?