C/C++ :: Accessing Functions And Objects Within Class From Main

Apr 28, 2015

We are coding a Blackjack/21 game. I have a Deck.cpp class, Deck.h, Play.cpp (holds Main), and Card.h (holds card struct). I also have a Hand class/header, but I'm not using it yet. This is what is required per instructor.I am having issues accessing the functions that are in my Deck class. I have tried a few other means to access the class's function, but I've already gotten rid of those. These three are my latest attempts with the specific errors in the comment on the line the error was happening.
ve.

Here is my Deck.h

#pragma once
#include <iostream>
#include <fstream>
#include <string>
#include <cstdlib>
#include <ctime>
#include <iomanip>
#include "Card.h"
#include "Hand.h"
using namespace std;
class Deck

[Code]...

View 3 Replies


ADVERTISEMENT

C++ :: Accessing Class Variables In Main

Apr 16, 2014

I am not able to access the class variable noof_vertex in the function merge , the error is the variable is private . below is the code :

#include <iostream>
#include <ctime>
#include <cstdlib>

[Code]....

View 1 Replies View Related

C++ :: Video Game - Accessing Objects In Another Class?

Dec 3, 2014

I am working on a video game that is based on a tutorial I found online and I ran into an issue associated with accessing an object's method inside another class object's function without making the object global which seems bad.

Here is basically how the tutorial set things up in the game: The game has a base class called GameObject then there are other child classes that inherit from this class. The GameObject class has all the basic information an object would have that needs rendered on the screen (x/y position, size of bitmap, bitmap, whether or not it is collidable, etc).

One of the child classes SpaceShip, which is the player so it has attributes and methods associated with managing # of lives and points scored.

There are other child classes of GameObjects in the game that need to take life and add points from the SpaceShip object if they collide with the spaceship or other objects.

In the collision handling routine I basically call a function "void Collided(int objectID)" when a game object collides with another. Within the Collided() routine, there is logic that executes code or other functions based on the objectID it collided with. Some of the collisions require taking life from the spaceship or adding points. The way this was accomplished in the tutorial was with function pointers (see Bullet class constructor and collided method for example). Is this really the best way to handle this sort of thing? It seems like there has to be a simpler way than to keep referencing function pointers in any new class I want to add to the game. I realized this when I went to add a method for the spaceship to fire bullets rather than inside my game class.

My Project Source found here: [URL] .....

View 5 Replies View Related

C++ :: Accessing Class Functions In A Vector?

Jul 24, 2013

How I can use class functions in a vector. I have 2 classes:

Gamemode class
bullets class

Inside the Gamemode class I declared: vector<bullets> Bullet and bullets * b.

If the user presses the shoot button a new bullets class will be added to the Bullet vector:

b = new bullets;
Bullet.push_back(b)

Bow I'd like to check all objects in the Bullet vector for the collision() function inside the bullets class.

I already set up a for loop which counts from 0 to the end of the vector:

for( int i=0;i<Bullet.size;i++)
{
}

My idea was to do something like:

if(Bullet[i].collision()) then erase Bullet[i]

But that doesn't work...

View 2 Replies View Related

C++ :: Accessing Private And Protected Member Functions Of Class?

Mar 30, 2013

how to access the private and protected member functions of the class.....

View 5 Replies View Related

C/C++ :: Passing Var Assigned In A Class File To Functions Outside Of Int Main?

Dec 7, 2014

I'm trying to pass the value of an object created from a class file to a function outside of the "Int Main" function in the main.cpp file. I've successfully created the object, I just want to pass it to a void function but I'm getting the scope error below. I'm not sure how to correct. I'm not having much luck with research either (static variables?).

error: 'TicTacToe' was not declared in this scope

main.cpp
#include <iostream>
#include <cstdlib>
#include "Signature.h"
#include "Gameplay.h"
using namespace std;
// Initialize array
char square[10] = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9'};

[code]....

View 4 Replies View Related

C++ :: Accessing Objects Within Another Object

Feb 8, 2014

I'm currently trying to access a variable contained within a base object from another completely different object and I continually get error messages. I'll attempt to put up the important code since it's contained within fairly large classes. From the Base .cpp file. ObjectPosition:

void ObjectPosition::init(float x,float y, float speed, int boundx, int boundy, float hit, int lives, bool live) {
ObjectPosition::x = x;
ObjectPosition::y = y;
ObjectPosition::speed = speed;
ObjectPosition::boundx = boundx;
ObjectPosition::boundy = boundy;
ObjectPosition::hit = hit;
ObjectPosition::lives = lives;
ObjectPosition::live = live;
}

This is the initialization function for the BaseObject. All objects are inheriting these variables which are Protected within the ObjectPosition class.Then they are initialized within the Pig class thus wise:

void Pig::binit(float sx,float sy, ALLEGRO_BITMAP *simage) {
//Sets all ObjectPosition Variables
ObjectPosition::init(800,900,10,80,40,40,10,true);
smaxFrame = 4;
scurFrame = 0;

[code]...

I tried to initialize the boundx through the pig via pinitx but I get errors and I can't access through the pig to the object position to the boundx.

View 10 Replies View Related

C++ :: Accessing Vector Objects Via A Pointer?

May 9, 2013

I have a pointer to a vector of objects, each object has an array and a couple of strings. how to access the data in the objects via the pointer.

Best tree::chooseSplit(vector <pgm> *ptr)
{
Best splits;
cout<<ptr[1].filePath; //not working!!!
}

filepath is a string in the pgm object. i also need to be able to access elements in an array that also exists in pgm.

View 2 Replies View Related

C :: Accessing Static Functions In Header Via Macro

May 11, 2013

Just wandering, will something like this work? header

Code:

#define func(arg) func_(arg) ...
static void func_(arg); code Code: #include "header"
int main()
{
func(arg);
}

View 1 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 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 :: Write A Program With Two Functions Both Called From Main

Mar 14, 2013

Write a program with two functions both called from main(). The first function just prints "Hello". In the second function ask the user to enter a number. Calculate the square root of the number and return the result to main(). In main() print the square root value.

Code:

#include<stdio.h>
#include<math.h>
float fun3 (float );
main()
}

[code]...

View 3 Replies View Related

C++ :: How To Implement Main Queue Functions Using Two Stacks

Nov 8, 2014

How to implement the main queue functions Enque() and Deque() using two stacks S1 & S2. You allowed only to call push () and pop() functions of the two stacks to implement Enque()and Deque() functions.

#include<iostream>
using namespace std;
const int size=5;
int arr[size];
int front=-1,rear=-1;
bool isfull() {
if(rear==size-1)

[Code] .....

View 4 Replies View Related

C++ :: Program To Display Other Functions In Int Main Function

Oct 13, 2013

I would like my program to display other functions in the int main function. For example, this is what my program looks like:

int Function1(int &var1, int &var2, int &var3) {
cout << "blah blah blah" ;
cin >> var1 ;
var2 = var1 * 3 ; //example
var3 = var1 * var2 ; //example
if(blah blah blah)

[Code]...

View 2 Replies View Related

C/C++ :: Main Function Can Only Declare Variables And Functions

Mar 9, 2015

I need making my main function to run while not having any if or for statements. It can only declare variables and functions. Since my main function has command line arguments, how to so.

// This program counts all the words in a given file.

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main(int argc, char* argv[]) {
FILE* txtFile = NULL; // File Pointer
char str[1000000];

[Code] ....

View 5 Replies View Related

C++ :: Using Member Function Of A Class In Another Class And Relate It To Object In Int Main

Aug 21, 2013

I am writing a program which is using SDL library. I have two different classes which one of them is Timer Class and the other is EventHandling Class.

I need to use some member functions and variables of Timer in some Eventhandling Class member functions, Although I want to define an object of Timer in int main {} and relate it to its member function that has been used in Eventhandling member function in order that it becomes easier to handle it, I mean that I want to have for example two objects of timer and two objects of Eventhandling class for two different users.

I do not know how to relate an object of a class from int main{} to its member function which is being used in another class member function.

Lets have it as a sample code:

class Timer {
private:
int x;

public:
Timer();
get_X();
start_X();

[Code] ....

View 4 Replies View Related

C :: How To Make Main Function Only Allowed To Declare Variables And Functions

Mar 6, 2015

So I need to make a main function have no if/for/etc. statements so I need to move it to another function and call it in main. The problem is that it's a command line argument function so I'm confused on how it works. Here's an example:

Code:

#include <stdio.h>
int main(int argc, char* argv[])
{
printf("The program name %s", argv[0]);
if (argc == 2) {
printf("Argument supplied is %s", argv[1]); }
else if (argc > 2) {
printf("Too many arguments");}
else {
printf("One argument");}
}

How can i make this into two functions with main only declaring variables and calling other functions?

View 2 Replies View Related

C :: Functions That Declare Arrays In Function Input Even Though Already Declared In Main

Mar 6, 2015

I have seen functions that declare arrays in the function input even thou the arrays is already declared in main. Why do you do this?

For example:

int ova(int antal, char glosorSv[][MAX], char glosorEn[][MAX])
int main(void)

char glosorSv[][MAX]
char glosorEn[][MAX]

View 2 Replies View Related

C++ :: Game Design Practice For Accessing Container Of Game Objects

Dec 21, 2014

I'm working on my first video game. So far I have a few classes in the game starting with the Game class which includes a list of GameObjects (another class). There are several classes that inherit from GameObjects used to implement things like bullets, explosions, various enemy types, etc.

The game essentially iterates through the list of GameObjects to update/render them. I would like to provide access to the Game's list of GameObjects inside another class (like the Bullet class) so I can put new objects on the list. For example, when a bullet hits, I want to add an explosion to the Game's GameObject list it can be updated/rendered.

How this should be setup? I was considering adding a pointer to the Game or GameObject list to the GameObject class (and methods to access it), but I was wondering if there is a better way to set this up?

View 4 Replies View Related

C++ :: Objects Interaction With Functions?

Mar 1, 2014

I am preparing for an exam, and I am being told there will be, "1 multiple-choice question about reading a piece of code about objects interacting with functions and deciding the output."

There are a few ways I can think of:

- Passing an object into a function as an argument
- An object calling a function with a dot operator
- Creating a new object through a Constructor and Class(Does that count?)

Are there other ways that objects interact with functions that I am not thinking of?

View 1 Replies View Related

C/C++ :: How To Access Linked List Functions From Stack Class Without Functions

Mar 20, 2014

I'm a little confused by my programming assignment this week. I've been working at it Wednesday and I've made progress but I'm still confused as to how I'm supposed to do this. The class I made is called Stack, and it's derived from a template class called StackADT. We also utilize a class called unorderedLinkedList, which is derived from a class called linkedList.

We're supposed to implement all of the virtual functions from stackADT in the Stack class. The Stack data is stored in a an unorderedLinkedList, so what I'm confused by is how to implement a few of the Stack functions because there are no functions in unorderedLinkedList which we could call to manipulate the data.

As you can see from my attached code, I'm really confused by how I'm supposed to implement the pop() and top() functions, and I also think my initializeList() function is wrong. We don't have any similar functions in unorderedLinkedList to call, so I'm at a loss of how i'd access my unorderedLinkedList. My initial thought was to call the similar functions in the class that unorderedLinkedList was derived from, linkedList, but I'm unsure of this is what we're supposed to do, or if theres actually a way to access my unorderedLinkedList without having to use the functions from the base class.

NOTE: We're not allowed to modify stackADT, unorderedLinkedList, and linkedList.

Stack.h

#include "stackADT.h"
#include "unorderedLinkedList.h"
template<class Type>
class Stack: public stackADT<Type>{
template <class T>
struct nodeType
{
T info;
nodeType<T> *link;

[Code]...

View 3 Replies View Related

C/C++ :: Array Of Functions Pointing To In Class Functions With Arduino

May 3, 2013

At the moment im trying out with pointing to an array of functions. I got this working as following:

typedef void (* functionPtr) ();  
functionPtr functions[2][2]={{do11,do12}, {do21,do22}};    
void do11(){DEBUG_PRINTLN("11");}
void do12(){DEBUG_PRINTLN("12");}
void do21(){DEBUG_PRINTLN("21");}
void do22(){DEBUG_PRINTLN("22");}    
void loop(){
         A=0;
         B=1;
         functions[A][b]();
}  

But now I'm trying to use this to point to a function inside a class so instead of do11, i want to be able to point to Basic.Do11. Somehow this doesnt work and I keep on getting this message:

error: argument of type 'void (Basic::)()' does not match 'void (*)()'

View 2 Replies View Related

C :: Accessing Variable From Other Class

Feb 19, 2013

Here is the link for my program, I want to access the average value which is located in grade.c (calculate_grade) class through driver.c (main function) but I don't know how to make "average" visible

[URL] .....

View 1 Replies View Related

C++ :: Accessing Variables Of Another Class?

Aug 3, 2013

I've been attempting to create a game with curses and I keep running into the problem of scope. I want to change or use variables of a different class in a different header file. But I don't know if I should use pointers, references or neither. Should I be programming in a manner that doesn't make it necessary to use variables outside of their class?

View 1 Replies View Related

C/C++ :: Accessing Private Class?

Apr 4, 2014

I am trying to access the private member from main . The code is as follow. I wanted to call below function from main.

uint16_t Modbus::calcCRC(uint8_t u8length)
#define MAX_BUFFER 64
typedef struct {

[Code]....

View 1 Replies View Related

C++ :: OpenGL - Outlining Functions Incorrectly When Used With Overlapping Objects

Oct 26, 2013

[URL] This program is creating an outline for each of the tall rectangular prisms that will eventually make up terrain in a game I am making. As you can see in the middle of the picture, the line is not fully connected, and it has smaller lines making up the bigger line like a dotted line. However, this only occurs when two objects overlap (in the part with the dotted lines, the two prisms are touching, as two of their vertices are the same).

How would I make the dotted line go a away and give me a solid line?

Here is my rendering code:
[spoiler]
glDepthFunc(GL_LESS);
glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
glBegin(GL_QUADS);

[Code].....

View 1 Replies View Related







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