C++ :: Passing Both Private And Public Variables-functions?
Mar 6, 2015How to properly pass both private and public variables/functions from one class to another?
View 3 RepliesHow to properly pass both private and public variables/functions from one class to another?
View 3 RepliesI've been writing my own implementation of quicksort in a .h file. I've gotten to the point where I think I'm done with the algorithm, so now I'm trying to make it so that if someone includes "quicksort.h", they will only have access to certain functions in the file. Kind of like public and private functions in a class, but without the "class" part of it. How do you do that?
View 7 Replies View RelatedI have this code where I am trying to retrieve the contents of the variable dev1 and dev2. for some reason when i compile and run I am getting 0 and 0.
Code:
typedef struct {
uint32_t x;
uint32_t y;
} sample;
void get_sample(sample *one)
[Code].....
I need passing some variables between functions. Here is the first part of the code which does work.
#include <iostream>
#include <iomanip>
#include <string>
using namespace std;
struct CarType {
string maker;
[Code] ....
Now the book says to take the following program and add a member function to the CarType class which prints the values of all of its data members. Add two more data members which are relevant for cars. Add the use of these data members to the program (to the assignment statements for MyCar, to the operator prompt and input inside the getYourCar function, and to the print function you have created).
Here is my code. Whenever I run it, it takes my assigned variables in MyCar and prints those instead of the one which the user is inputting.
#include <iostream>
#include <iomanip>
#include <string>
using namespace std;
using namespace std;
struct CarType {
string maker;
[Code] .....
I've finally managed to do something with the combo box but knock down one wall it's like there's another one five inches behind it. What I mean is I've figured out how to add items to the combo box and have them show images in my picture box. Only problem is when I went to debug my combo box kept looping it's options over and over and over.
Private Sub
xpmaleskincolorselect.Items.Add("Tone1"); malesprite.Image = My.Resources.Resources.XP_Female_clear;
xpmaleskincolorselect.Items.Add("Tone2"); malesprite.Image = My.Resources.Resources.XP_Male_tan;
xpmaleskincolorselect.Items.Add("Tone3"); malesprite.Image = My.Resources.Resources.XP_Male_dark;
End Sub
The subs, I know they aren't right but its just to show I know where they go. Anyway using Private Sub and End sub doesn't seem to work. I'll type them in then at the error box at the bottom it'll say that it doesn't exist in the namespace. Same thing happened when I tried to add public class beforehand to see if that would work same thing about the name space.
I need to translate a C program to C by making variables in structures private(no classes yet!) and putting public inline functions. There's a good chance that I have much more problems with my code than I'm asking right now, but I have 4 spots that I'm currently stuck in and can't access properly.
My structures:
Code: struct Container
{
private:
int count;
char** lines;
int nlines;
[Code] .....
I am writing a bit-check function just to make it easier on myself to check status flags in my classes. I use char variables and each bit represents something on or off. Since I have numerous classes that will use this functionality, it makes sense to write and compile the code only one time rather than for each class. I was thinking of writing the function and including it as a "friend" function to each class that needs it. Is that an appropriate way to do it?
View 2 Replies View RelatedHow would I change the private variables in the header files and the code in the cpp files for the primary indexes so they use a dynamic array or vector instead. For the primary index, the initial vector size will be 8.
header
#ifndef MY_PRIMARY_INDEX_H
#define MY_PRIMARY_INDEX_H
#include
#include
#include
#include
class PrimaryIndex
[Code] ....
I'm unable to access private variables belonging to the object class Date, which my overloaded >> operator is a friend of. I can't see anything in my code that would be causing this error. The .h file and the definition of the problematic overloaded operator from the implementation file are below:
#ifndef DATE_H
#define DATE_H
#include <string>
using namespace std;
class Date {
public:
// Initializes a date to the default value of January 1, 1970.
[Code] .....
The error message states that the vars (month, day, year) are declared as private in the header file and then a reference is made to the lines where I attempt to access these in the .cpp file and it reads: "in this context".
how to access the private and protected member functions of the class.....
View 5 Replies View RelatedThis is my first time working with C++ and I have put together this program and came up with two errors and I am unsure what it is wanting me to do. The errors I got are:
1>c:usersownerdocumentsvisual studio 2010projectsweek5week5passing_by_value.cpp(30): error C2064: term does not evaluate to a function taking 1 arguments
1>c:usersownerdocumentsvisual studio 2010projectsweek5week5passing_by_value.cpp(38): error C2064: term does not evaluate to a function taking 1 arguments
#include<iostream>
using std::cin;
using std::cout;
using std::endl;
[Code].....
ok I have a class Player with lots of variables and im gonna call a function to checkXp, if I call it with the whole player object does it use a lot more memory then if I just passed the couple things I need?
ex
checkXP(Player* play) // this is a whole object of player
or
checkXP(play->getXP(), play->getLVL()) // the variables I want.
I just realized I may not be able to modify anything from player in the checkXP() function
question 1: does passing the whole object use more memory
question 2: if I passed as just the variables I need, I wont be able to modify anything of object play?
Well I have my program running and the Variables are not passing correctly and the return statements are not returning correctly. Here is the parts that are not working.
#include <iostream>
#include "fight.h"
#include <time.h>
#include "player.h"
#include "stdlib.h"
#include <cstdlib>
using namespace std;
combat A;
combat::combat(void)
[Code] ....
I define an integer variable and pass it by reference to a function.
int func(int &x)
{
// do something
}
int x;
func(x);
However, I have not only one variable but an array of variables with its predefined name. How do I pass to the function by using loop? Example:
int x, y, z;
func(x);
func(y);
func(z);
How can I do this by using loop?
I'm trying to use two variables for two different functions.
#include "stdafx.h"
#include <iostream>
#include <cstdlib>
[Code].....
Every time screen2() runs it always outputs "Numbers entered were 0 and 0". I want the numbers that were entered in by the user in screen1() to be displayed.
I have a main thread and a worker thread. How do i pass data between them when both are already running without using global variables?
View 1 Replies View RelatedI'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?
I'm truing to write a function that gets an array of arrays, and returns an array. I placed the code I'm using below, but I'm getting all kinds of errors. How is the right way to do this?
static void Main(string[] args) {
int[] draw1 = new int[] { 5, 8, 3 };
int[] draw2 = new int[] { 3, 6, 8 };
int[] draw3 = new int[] { 6, 7, 9 };
int[] draw4 = new int[] { 5, 6, 0 };
[Code] .....
In the code below there is some error, I think it is related with functions. It compiles properly but then it outputs only : "humanslife8.90145e+032"
#include <iostream>
#include <windows.h>
#include <stdlib.h>
using namespace std;
void userInput(float HumanNumber, float SkeletonNumber, float AllHumanslife, float AllSkeltonslife, float SkeletonHealth, float HumanHealth);
void HumansTurn(int turn, float HumanAttack, float AllSkeletonslife, float HumanNumber, float HumanDamage, float SkeletonHealth, float SkeletonNumber);
[code].....
I have the main() - which has entries like
Code:
main() {
int ss, ret, z;
float yy;
ret = function1(&yy, &ss, &z);
//int function1(flat *cc, int *dd, int *k) - is it correct?
[Code]...
forget everything from before. It came out of confusion regard the supplier functions. dis_s() and read_s() the part functions work and are not any different really.
Code:
#include <stdio.h>#include <stdlib.h>
#include <string.h>
#define MPS 10 //Max Part Size
#define MSS 10 //Max Supplier Size
}
[code]....
when I run the dis_s() function it just prints out garbage until it segments. starts with a bunch of 0 and newlines until it starts printing locations on my computer...... it worked on campus with debian and I only copied it from gmail to my computer so I really don't understand whats up(im on mint).
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] .....
I have a main dialog which has (DDX?) controls for the user. eg a slider, and a combo box.
Previously, an image adjusted by these controls was in the same dialog.
I need to put this image in a New, separate dialog but it still must be controlled by the slider and combo box on the main dialog.
My question is how can I pass the control's variables between the dialogs? I have, say,
Code:
//MainDlg.cpp
DDX_Control(pDX, IDC_ComboBrightness, m_Brightness
I was told that I could do something like:
Code:
//ImageDlg.h
public:
ImageDlg(CWnd* pParent = NULL, CComboBox m_Brightness); // standard constructor
But I get errors including: Missing default parameter for parameter 2
I also need to pass the image array, is that perhaps the same method?
Having a little trouble passing arguments to functions.
I wrote this simple program to get the hang of it but I'm quite stuck. I'm sure you will be able to get at what i want the program to do...
Code:
#include <conio.h>
#include <stdio.h>
#include <ctype.h>
#include <string.h>
#include <windows.h>
void menu(int HP,int Gold,int Armour);
[Code] ....
I have been struggling with pointers. I am trying to write a program that first asks a user to input a filename. It then checks if the file exists and if it does it passes a pointer to the next function. The next function then asks the user for a specific word to look for and the function will search a text file for the word and do some other operations. My problem is that I do not understand how to use the pointer returned by my first function as an input to another function.
The following code has the first function file_check() and the second function word_search() which I think the way I am declaring it is the problem.
Code:
FILE *file_check();
void word_search(FILE *);
int
main(void) {
FILE* check= file_check();
// word_search(check);
[Code] ......
i have a program that works, but now I am trying to get function1() to work. What it has to do is bring in the array and populate it with random letters. I don't know much about functions.
Code:
#include<stdio.h>
#include<stdlib.h>
#include<time.h>
#define maxrow 20 //defines maxrow as a constant of 20
#define maxcol 30 //defines maxcol as a constant of 30
}
[code]....