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


ADVERTISEMENT

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 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

C/C++ :: Files Interaction With Software

Mar 23, 2013

It is commonly seen that computational applications accept data in notepad or excel formats to do the process on. The question is how would they do that? Do they store the notepad data somewhere in the application memory or they interact with the notepad file all the time program is running? This is my first try developing a small application .

View 1 Replies View Related

C++ :: Digitize Geographical Map Through GUI And Mouse Interaction

Jul 8, 2012

I am developing an application which can be used for digitize a geographical map through GUI and mouse interaction. Well, here are the list of objects that need to be created using mouse clicks.

1) Points
2) Polyline
3) Polygon
4) Rectangle/Square
5) Ellipse/Circle
6) Text

What will be the best design which can be used to store the data(objects) more efficiently? So that both accessing objects and rendering them will be easier and faster? I have started with Composite Design pattern to store the objects and Visitor Design pattern to render these objects.

[Code] .....

But everytime rendering is done sequentially. Will not this take more time if the number of objects increases?

View 7 Replies View Related

Visual C++ :: Interaction Between Algorithm And Winsock

Jul 24, 2013

Code:
#include <algorithm>
#include <winsock.h>
void some_func() {
int result = std::min (0, 16384);
}

Okay, but the above code consistently gives me error C2589: '(' : illegal token on right side of '::'. I'm building with VC8. If I don't #include <winsock.h> the code compiles correctly but it doesn't matter if I #include <winsock.h> before or after including <algorithm>

I guess it might be due to one of my #defines but I've tried the code in a very minimal program and I still get the error.

View 7 Replies View Related

C++ :: Application To Load Other Applications In A Secure Shell Based On User Interaction

Jul 9, 2013

I will sketch the scenario I would like to get working below. I have one main application.

That application, based on user interactions, can load other applications in a secure shell. This means these child applications cannot interact with the OS anymore, nor with each other.

The parent program can at any time call functions of these child programs.

The child program can at any time call functions of these parent programs.

How to implement this in C++? Preferably both parent and child should be written in C++.

The performance of loading the child applications doesn't matter. The only thing that matters is the performance of the communication between child and parent.

View 4 Replies View Related

C/C++ :: Objects Hold References To Other Objects?

Nov 12, 2014

This has been bothering me for a while now, and I finally put together an example:

#include <iostream>
#include <string>
using namespace::std;

[Code]....

In the code above, the two classes hold pointers to each other, and that's fine but it doesn't seem right since C++ prefers to pass by reference. Yes, it can still do that (see testbox and testball) but even that seems odd to me because still you need to use pointer notation for the enclosed object. Am I the only one who feels this way, and should I just get over it? Or am I missing something that would allow an object to hold a reference?

View 4 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++ ::  attraction Between Objects

Apr 2, 2013

i am relatively new to c++, and am trying to make it so particles will gravitationally attract to the mouse pointer. i have gotten all the bugs that the compiler found, but there must be another because the program crashes the second i open it. my code could be way off, so just tell me if it is and ill do more research and learning before trying something like this again. here is the code:

#include <SDL/SDL.h>
#include <iostream>
#include <vector>
#include <math.h>
#include <stdio.h>
using namespace std;
float mouseX;
float mouseY;

[Code] .....

View 6 Replies View Related

C++ :: The Proper Way To Do A Vector Of Objects

Oct 20, 2014

I've been really busy but managed to get in enough down time to learn somewhat decent info about vectors. Anyways originally my program created a dynamic array of pointers to class objects and I came across a few problems because of this. Apparently an array of pointers is now outta of the question and I will now be switching to a vector of objects instead.

Why I want a list of objects instead of pointers this little comment should clear things up.

tiles[i]->show() dereferences tiles[i] (i.e. accesses whatever it points at) before calling the show() method.

That is undefined behaviour. Once undefined behaviour occurs, there is no recovery, and there is nothing the show() method (or any subsequently called function for that matter) can do to recover (short of invoking their own forms of undefined behaviour - compiler specific hacks, etc).

Even if the show() method initialises the object correctly, it cannot change the pointer tiles[i] which is in a different scope (within main()).

What I'm trying to do is create a vector of already intialized objects so that I can use a conditional statement of every single element to properly layer my games art resources. This should also automatically fix a mild unrelated collision dectection problem too but first thing first layering.

View 9 Replies View Related

C++ :: How To Delete The Objects Within A Vector

Nov 10, 2013

here's the problem. I want to delete the objects within a vector, although I'm not sure whether I should clear the vector afterwards. Is it really necessary?

Code:

for (i = 0; i < allSales.size(); i++)
delete allSales[i];

allSales.clear(); //Is this step necessary?

View 5 Replies View Related

C :: How To Compile Objects In A Subdirectory

Aug 25, 2013

well the question is how to compile objects in a subdirectory?

Code:

./bo/%.o : %.c
$(CC) $(CFLAGS) <$

the command abouve will compile my objects but leave them in the same directory. However I want them in a different directory. in ./bo directory. How to achieve that ? I just realize that if i remove ./bo/ from the line it does not work..

View 3 Replies View Related

C++ :: Assignment Of Objects To Pointers

Jun 6, 2013

I am using OpenCV to read and manipulate a set of images, which I need to store in an array to work with them. Here is a snippet of the code:


#define MAX_IMAGES 8
typedef Mat* MatPtr;
int main(int argc, char** argv) {
char imageName[] = "./res/imageX.tiff";
MatPtr datacube[MAX_IMAGES];

[code].....

I have an array of pointers to Mat objects (an OpenCV class used to hold info and data about an image), which I will use to store the images. The function imread reads an image and returns a Mat object loaded with the relevant data about the image.However, this gives me a nice segfault when the assignment takes place. Of course, I can swap it with the following code, but since I'm working with big images (2048x2048 and upwards), it's really inefficient:

for(unsigned int i = 0; i < MAX_IMAGES; i++) {
imageName[11] = 49 + i;
datacube[i] = new Mat(imread(imageName, -1));
}

Is there any way to do this elegantly and without much hassle?Again, excuse my rustiness and anything completely stupid I might have said. It's been a long time since I worked with C++. Managed to circumvent the problem by using a STD vector instead of an array. I'd still like to know the answer to this riddle...

View 6 Replies View Related

C++ :: How To Use Class With Array Of Objects

Oct 12, 2014

class FlashCard {
public:
int a,b;
void PrintCard(void);
int CorrectAnswer(void);
};
void SwapFlashCard(FlashCard &a,FlashCard &b)

[Code]....

Why does Xode warn me that Type'FlashCard'does not provide a subscript operator on line 22,23,29 and 30?

View 7 Replies View Related

C++ :: Access Objects From Another Thread

Jun 25, 2013

I have the following code below. I am getting a memory access violation when accessing cmd->query_string in the loop function. The loop() function is running in another thread. The cmd object appears to be destroyed after calling the send_command function. How do I create an object on the heap and access the query_string.

std::list<my_command_message_que*> my_command_que;
void loop(){
if(my_command_que.size() > 0){
my_command_message_que * cmd = my_command_que.front();
std::cout << cmd->query_string;

[Code] ....

View 2 Replies View Related

C++ :: Bad Value Result From Operator Using Objects

Jul 24, 2013

I keep getting an undesired value in this code. I've tried several methods, but none are giving me the correct answer. The out put is always zero, when in this case it should be 10!!

Here's the object structure:

template<class T, class _b>
struct quantity {
private: T value;
public:
explicit quantity(T val): value(val) {};
T getValue() { return value; };

[Code] .....

Here's the operation:

int main() {
quantity<int, bool> m(20);
quantity<float, bool> m_f(10);
quantity<double, bool> m_d(NULL);

m_d = m_f;

[Code] .....

Why does it seem that the assignment operator is the harder operator to overload? Maybe it's just my luck, but I seem to always run into issues whenever I work with it. I hardly ever experience errors when overloading any of the other operators.

View 6 Replies View Related

C++ :: Headers And Objects Files

May 20, 2013

I have a question regarding how GCC relates a header file and its binary file.

main.c
#include <math.h>
#include <stdio.h>
int main (void){
double x = sqrt (2.0);
printf ("The square root of 2.0 is %f
", x);
return 0;
}

we can compile it by running the line: gcc main.c -lm -o main

My question is: How GCC knows where is the definition of sqrt?

First I was thinking that there was and object file with the name math.o inside libm.a (that is GCC will look for an object file with the same name as the header file), but after running the next line I think my assumption was wrong as there is not such file in libm.a.

nm libm.a | grep math.o
nm: e_acos.o: no symbols
nm: k_cos.o: no symbols
nm: k_sin.o: no symbols

[Code] ....

View 7 Replies View Related

C++ :: How To Store Objects To Program

Nov 14, 2013

I've started programming my little program called vLibrary (program I want to make for the library in my city) and after I m done with console application I will try to implement wxWidgets.My program will be able to add new users to the system, new books and new librarians.

Now, I m confused what data types to use and how to store objects (newly created users, books etc) to my program so later on they can log in the system etc. Logic of the program is completely clear to me but I m not sure how to make array of objects and store them in memory or in a certain file, how to store password and make some kind of encryption etc.which data structure from STL should I use and how.

View 2 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++ :: Looping Through Template Objects In Map

Dec 30, 2014

How to get this code working

template <typename T>
class Dummy {
// Implementation
};
template <typename T>
class SomeClass

[Code] ......

View 4 Replies View Related

C++ :: Storing Objects Using Vector

Oct 31, 2014

I have two classes, Parent and Child, where Parent contains a vector that is used to store instances of Child. When I create an instance of Parent, three instances of Child are also created in Parent's constructor and stored in the vector. I understand that push_back() creates a shallow copy of each Child instance and that Child's destructor is called each time the loop (inside Parent's constructor) iterates. The problem is that because Child's destructor is called each time the local variable child goes out of scope, the memory previously allocated in Child's constructor is destroyed and when Child's destructor is called again later on in the program to get rid of the copy stored in vector, the program crashes. I can fix this by overriding the default copy function or by storing pointers to objects instead of copies of objects. I don't really need to use vectors in this case since I always have three children in one parent but I'm doing this as a learning exercise and would prefer to use vectors.

#include <iostream>
#include <vector>
class Child {
public:
Child() {
std::cout << "child constructor called" << std::endl;

[Code] .....

View 3 Replies View Related

C++ :: Deposit Vectors With Different Objects?

Nov 6, 2013

I my code i have a base struct ...

Then others structs made ...

struct base{};
struct a1 : base {
int a;
int b;

[Code] ....

Now i must deposit all these containers(maybe & of containers) in another vector...

How i can do that? Can i write

vector<vector<base*> > all;
all.push_back(&v1);
all.push_back(&v2);

View 14 Replies View Related

C++ :: Using Array Of Pointers To Objects?

Sep 27, 2013

I've created an Array of pointers to objects using:

Person ** A = new person * [arraysize];

When I intend to access a specific person do I have to do this? :

something = A->[i];

and when I want a specific object within my struct do I have to do this? :

something_else = A->[i]->random_int;

View 10 Replies View Related

C++ :: Store Address Of Objects

Oct 27, 2014

I'm using the SDL library and trying to match the C++11 standards... Anyway, I thought about a vector where I store all the addresses of game instances, so I can access them anytime... I tried with this function:

int instance_new(std::vector<uintptr_t> &instance_id, unsigned &instance_size, Instance *pointer) {
instance_id[instance_size] = reinterpret_cast<std::uintptr_t>(pointer);
instance_size++;
instance_id.resize(instance_size);
return 0;
}

Where "Instance" is the 'parent' class of various child classes like the player. So, if I have to search the existing of a thing in my game, I should check if the address references to an instance of class. How can I do this?

View 1 Replies View Related







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