C++ :: Getting A Value From Object Passing It To Array

Apr 17, 2014

I am writing a program for a poker game.. I created a class to get cards and create deck.. the problem I am having now is how to deal 5 cards to an array to ve evaluated later. I want to call the array player1[5]. I tried to use pointer but I get the following error

#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 4 Replies


ADVERTISEMENT

C++ :: Passing Object With Templated Static Array Into Another

Feb 3, 2014

This problem just seems really strange to me because it is simple yet for some reason my class cannot pass into another class. The class PASS_OBJECT has a static array (even with 1 element this doesn't work) and when I try to pass this class (after it is initialized) I seem to lose the data inside the PASS_OBJECT. Not only that but even when I declared the class OBJECT with the type of PASS_OBJECT<int> I seem to lose the integer 99. Here's the code, note that if you comment out line 89, 92 and 93 you will notice that line 90 outputs In main 2: 99 just fine but it doesn't otherwise???

#include <iostream>
const int size = 1;
template <class T>
class PASS_OBJECT;
template <class S>
class OBJECT {

[Code] ....

View 2 Replies View Related

C++ :: Passing Array Of Object Gives Compilation ERROR

Dec 21, 2012

This is my question : Define a class named HOUSING in C++ with the following descriptions:

Private members
REG_NO integer(Ranges 10 - 1000)
NAME Array of characters(String)
TYPE Character
COST Float

Public Members
-Function Read_Data( ) to read an object of HOUSING type
-Function Display() to display the details of an object
-Function Draw Nos( ) to choose and display the details of 2 houses selected randomly from an array of 10 objects of type HOUSING Use random function to generate the registration nos. to match with REGNO from the array.

Now I' trying to do this by this way

Code:
#include <iostream.h>
#include <conio.h>
#include <stdlib.h>
class housing {
private:
int REG_NO;
char NAME[10];

[Code] .....

I am trying to pass the entire array of object in DrawNos(). but getting compilation error -

32: 'housing:rawNos(housing * *)' is not a member of 'housing'
48: Structure required on left side of . or .*

What is the problem? How can I pass the array of object in function and use it.

View 3 Replies View Related

C++ :: Passing Object By To Queue

Dec 4, 2013

I've been working on a little project and hit a snag. I'm using nodes for a queue and stack class that were created using an existing list node class. I create an object for a student class and I want to enqueue that object.

int main() {
Queue sLine;
Customer stu;
Queue<Student &>
cLine.enqueue(cust);
}

That's basically the coding of it in main. However when I follow the error which says uninitialized reference member ListNode<Student& info>::data;

#ifndef LISTND_H
#define LISTND_H
template< class T > class List;
template< class NODETYPE >
class ListNode {
friend class List< NODETYPE >;

[Code] .....

What I may have been doing wrong? Trying to work within certain contexts.

View 2 Replies View Related

C++ :: Passing Object Into A Function

Feb 13, 2013

This is supposed to check for valid input

if(((c.integer < 0)&&(c.numerator < 0))||(c.denominator<=0)) {
c.integer = 0;
c.numerator = 0;
c.denominator = 0;
}
if((c.integer>0)&&(c.numerator<0))

[Code] ....
And it does just fine, until it's passed into a function, then it doesn't work:

void validInput(Mixed a) {
if(((a.integer < 0)&&(a.numerator < 0))||(a.denominator<=0)) {
a.integer = 0;
a.numerator = 0;
a.denominator = 0;

[Code] ....

It works, when the object is passed, except for two cases (one where the minus sign shifts) and whenever there is a zero or a negative integer in the denominator.

Also, I'm passing the function like validInput(c);

View 4 Replies View Related

C++ :: Passing Ifstream Object Between Functions

Mar 29, 2013

Code:
void lexer(ifstream& inputfile) {
string line;
getline(inputfile,line);

[Code] ......

I am trying to pass input file between two functions. The code compiles but immediately upon running the program, there is a "bad cast" run time error.

View 9 Replies View Related

C/C++ :: Passing A Stream Object By Reference?

May 5, 2014

I need to create a function in my program to open an input file and another function to open an output file and I need to use the files in other functions so Im trying to pass the stream object by reference but then i need a condition that tells the compiler not to reopen the file because then it will delete everything and make me input the file names again. Heres the two functions.

void InputFileOpen(ifstream &inFile) {
string file_name;
if(!inFile.is_open()){
cout<< "Enter the input file name: ";
cin>> file_name;
inFile.open(file_name, ios::in);

[code]....

View 4 Replies View Related

C++ :: Error Passing Object Reference

Nov 23, 2013

Code:

#include <Data.h>
int main(int arg_count, char** argv) {
if(arg_count!=3){
cerr<<"Files misisng
";
exit(1);

[code]...

This actually should work, because it is passing address of polymorphisms object.I have tried changing prototype of test in Data.h, but failed.passing object address/pointers in C++.

View 5 Replies View Related

C++ :: Passing Object By Pointer To Function?

May 20, 2014

I have a Qt classes as follow:

Code:

class Vehicle {
public:
void AddData(QString str, Data* data) {
_myDataMap.insert(str,data);
} virtual void Init();

[code].....

My questions are:

After the main function called d1->Modify; the data stored in _myDataMap will get modified too.

What is the more appropriate way of passing the Data through AddData in such case?

If i do AddData(const Data & data), i will not be able to use inheritance of Data, i.e passing a subclass of Data to AddData.

View 3 Replies View Related

C++ :: Passing Fstream Object To Function

Jul 6, 2013

I want my function to take 'fstream' object as an input, so the program looks like this:

Code:
#include <fstream>
using namespace std;
void test(fstream a){
a.open("test2.txt");
a << "123" << endl

[Code] ....

But I get error: 'std::ios_base::ios_base(const std::ios_base&)' is private|

View 3 Replies View Related

C++ :: Ifstream Object Passing To Functions

Feb 29, 2012

I am having an issue with passing an ifstream object to functions. Here is the code:

Code:
#include <fstream>
using namespace std;
void otherfunction (ifstream *ifs) {
...does stuff, like ifs->open(), then reads from the file...
}

int main () {
ifstream ifs();
otherfunction(&ifs);
}

Here is the error message:

Code: error: cannot convert ‘std::ifstream (*)()’ to ‘std::ifstream*’ for argument ‘1’ to ‘void otherfunction(std::ifstream*)’

Why can't I do that? What does "ifstream (*)()" even mean? And I don't want to change the structure of the program. I have reasons for declaring the ifstream object in the main function (because there are actually two functions that need access to the ifstream object -- neither of which is working).

Also, if I change the main function to be this instead:

Code:
int main () {
ifstream ifs();
ifstream *ifsptr = &ifs; //EDIT 2: forgot the ampersand
otherfunction(ifsptr);
}

I get the same error as above. However, if I change the main function to this:

Code:
int main () {
ifstream *ifsptr = new ifstream();
otherfunction(ifsptr);
}

I get all kinds of crazy errors about "undefined symbols for architecture _____". Here is the actual error message from my program (parseArgs is the real name of otherfunction)

Code:
Undefined symbols for architecture x86_64:
"std::ios_base::Init::Init()", referenced from:
__static_initialization_and_destruction_0(int, int)in cchumGBV.o
"std::ios_base::Init::~Init()", referenced from:

[Code] .....

View 12 Replies View Related

C++ :: Passing Object To Inherited Class By Constructor

May 1, 2013

I am trying to pass an object to an inherited clas by a constructor. I am having Cboard my board and i need to pass it to the object Cpawn.

Here under is my code:

main
Code:
#include<iostream>#include "Cboard.h"
#include "Cpawn.h"
#include "Cpiece.h"

void main(){
char location[50];

[Code] ....

View 3 Replies View Related

C# :: Passing Object As Parameter Creates A Copy Of It

Dec 17, 2014

Here is my issue: I am making a simple audioplayer in Xamarin.android but i want every time i change the track to make a crossfade effect. So im using 2 mediaplayers at the same time for the fade. The problem is that im defining one time the players and i pass the player as a parameter like this:

public MediaPlayer player = null;
public MediaPlayer player2 = null;
....

If i have to fadeout the player and start the next one im doing it like this:

if (player != null){
if (player.IsPlaying) {
cts = new CancellationTokenSource();
token = cts.Token;
FadeOut (player, 2000 ,token);

[Code] .....

So my problmem is that player and player2 remain always null. Why? i guess c# creates a copy of player and player2 and use this one. How i can pass a mediaplayer as parameter and always use only player and player2?

View 8 Replies View Related

C++ :: Starting Vertex Array Object At Index Of Vertex Buffer Object

Sep 22, 2014

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;
//...

View 1 Replies View Related

C :: Print Values Of Array From Function By Passing Array?

Nov 1, 2014

I wanted to print the values of a array from a function by passing the array as well as the number of elements to be read. For a single dimensional array, this is how i have written it. It's pretty straight forward. I want to read 5 elements from the 5th element in the array.

Code:
#include<stdio.h>
void display(int array[],int size) {
int i;

[Code]....

With this code I want to print the five elements from the element present in [0][4].

But shows an error that

Code:
D:BennetCodeblocks CLearning CSingleDimentionalArray.c||In function 'main':|
D:BennetCodeblocks CLearning CSingleDimentionalArray.c|18|warning: passing argument 1 of 'display' from incompatible pointer type [enabled by default]|
D:BennetCodeblocks CLearning CSingleDimentionalArray.c|2|note: expected 'int (*)[10]' but argument is of type 'int *'|
||=== Build finished: 0 error(s), 1 warning(s) (0 minute(s), 0 second(s)) ===|

I know when you pass a array as an argument it gets decomposed into a pointer, but with a multi-dimensional array this is not the case. how this works for mult- dimensional array's?

View 3 Replies View Related

C++ :: Passing 2D Array To A Function Where Size Of Array Is Not Known At Runtime

Jun 27, 2014

I'm wondering if it is possible to pass a 2d array to a function where the size of the array is not known at runtime.

I've tried

function ( array[][6] ) ;

But the size of the array has to be constant so it cannot be declared later.

I've tried using a template but you still have to declare the size of the array at runtime. Is this even possible at all?

The only other way I can think of is using a dynamic 2d array but how to create one and manipulate it.

View 2 Replies View Related

C++ :: Passing Value Into Array

Apr 16, 2014

I am writing a program for a poker game.. I created a class to get cards and create deck.. the problem I am having now is how to deal 5 cards to an array to be evaluated later. I want to call the array player1[5]. So I tried to create a pointer called GetCard, and was hoping to then pass the value into the player1[] array. I tried to use pointer but I get the following error

4931[Error] void value not ignored as it ought to be

Code: #include <stdlib.h>
#include <iostream>
#include <ctime>
#include <algorithm>
using namespace std;

[Code] .....

View 9 Replies View Related

C :: Passing Array To Function?

Jul 31, 2014

I want to pass array to function, to fill array with new values and then to print the array in the main. But I have problem because it prints me just array of zeros. Maybe the concept is wrong, I'm new with passing arrays to function.

function:

Code:
void printSum(int *return_array) {
int return_array[3];
int i;
for(i = 0; i < 3 ; i++){
return_array[i] = 5;

Code:

void printSum(int *return_array);
int main {
int m_return_array[3];
int i,j;
for(i= 0 ; i < 3 ; i++){
m_return_array[i] = 0;
} printfSum(start,m_return_array);

[Code]...

View 1 Replies View Related

C :: Passing 2D Array To A Function

Sep 17, 2013

I need to pass a 2D array to a function. I want to know, where I may have made a mistake. This is the piece of code that I found on the web, and I am using it to allocate my 2D array.

Code:
signed char allocate2D( int** arr2D, int rows, int cols )
{
int i;
arr2D = malloc( rows*sizeof( int* ) );
if( !arr2D )
return -1;

[Code]....

My main function passes the 2D array to the function

Code: signed char read_root_message_file( int **Root_Messages, int *num ) This is how I pass the array in the main function to the above function:

Code:
int main( int argc, char *argv[] )
{
int **Root_Messages;
...
...
Root_Messages = NULL;
read_root_message_file( Root_Messages, &num_root_msg );

[Code]....

View 7 Replies View Related

C :: Passing Data From An Array And Using It In Another

Mar 18, 2014

I have been asked to write a lottery program in c using 5 separate functions 1 to take 6 numbers from user 2 to display the numbers 3 to sort the numbers 4 compare the chosen numbers to the winning numbers and 5 to list the frequency the user pick a number depending on how many times they play the game the problem im having is with the first 2 functions i can take the input and pass it to a display function but cannot get it to display the numbers here is what i have. The output from this is at the bottom .....

Code:
//function prototypes
int myNumbers();
void displayNums();
void sort();
void compare();

#include <stdio.h>
#define NUMS 6
#define WIN 7

[Code] .....

"Please enter your lucky numbers
1
2
3
4
5
6
Your numbers are 2286612"

View 1 Replies View Related

C :: Passing Array To A Function?

Apr 6, 2013

Would this be an example of passing an array to a function??

Code:

void wipe (int theArray[] ) {
int index;

printf("
Inside function wipe() sets each array element back to 0.
");

[code]....

View 4 Replies View Related

C :: Passing Array To Function

Jan 19, 2014

I am following a tutorial and the topic was passing array to function so i tried to do a BMI calculator by myself. I am using code blocks to compile the codes, it is actually working while using compiler's run button. But when I open the exe file, its closing the window after entering the persons' weights and heights. Here is the code

Code:

// Passing array to function example BMI calculator of n person
#include<stdio.h>
#include<math.h>
void assess(float bmi[],int a);
int main(void){
int n,i,j;
}

[code]....

View 4 Replies View Related

C :: Passing Struct Through Array

Apr 2, 2013

I am trying to pass a struct through an array to another array from one microprocessor to another microprocessor and then dereference that array to update the same exact struct on the other microprocessor.My goal is to always have values inside of both structs while sending any updates to the struct on the other microprocessor in the mean time but I seem to be looping through the data and the members of the struct seem to be cleared out after every clock cycle. I can verify this by the flashing of my leds which the struct controls.

FIRST MICROPROCESSOR

Code:

extern struct i2c_data * TX_Data;
extern struct i2c_data TX_Data_1;
extern struct i2c_data TX_Data_2;
}

[code]....

View 1 Replies View Related

C++ :: Passing Array To Function

Jan 8, 2014

I am learning arrays i want to whats the following effect of cods while passing array to the following function

void fun(array[])
void fun(array[4])
void fun(array[],4)
void fun(array[5],4)

View 3 Replies View Related

C++ :: Passing A Multidimensional Array

Sep 25, 2013

I'm trying to pass a two-dimensional array to a function. The function is defined as: long foobar(char foo[][CONST]); I have to create that array dynamically. Currently I do that this way: char* bar = new char[count * CONST];

But when I'm trying to pass the array I get a type conversion error. I tried a lot of different ways to pass the pointer and/or to allocate the memory, but apparently I didn't find the right way or combination of definition, allocation, casting and calling.I cannot change the definition of the function, which (IMHO) is pretty stupid. :(

View 3 Replies View Related

C++ :: Passing Array In A Function?

Apr 18, 2014

i have defined an object which is an array of my class called Player now i want to pass this whole array as a parameter in a function, i think it will be done by using pointers but i am not able to figure out how it is done?

Player player[4];
void showscoreboard(" ", int cround){}
" " represents the blank where the array should b passed.

View 9 Replies View Related







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