C# :: Can Use Variables From Other Classes

Feb 23, 2014

im creating an address book. One address book contains a ListBox, New User button, Edit User and Remove User button. The first form is suppose to allow you to view the users you've created on the ListBox and you can decide whether you want to remove it, create a new one or simply edit the user. Now The second form simply contains labels and textbox along with a save button. I'm having a bit of issue figuring out the ListBox. I want to be able to create a user and have the user be posted on the ListBox. I read that i must instantiate listbox then simply add it. Now on my form2 i have a for loop that loops through an Array of String were all the users will be created on. How can i call that array of string on to the form1?

Form 1:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

[code].....

EDIT:I just figured out that to call a variable from one form to another you simply instantiate the form then simply call it. PS. must be set to public:

ListBox1 createUser = new ListBox1();
createUser.userString[0];

why doesnt it show the windows when i run without debugging?

View 1 Replies


ADVERTISEMENT

C++ :: Static Variables In Classes

Mar 1, 2013

If I have a static variable in a class e.g. a pointer to another class like this: (B is another class)

class A {
public:
static B* cB;
};

Then I set that variable and create multiple instances of class A like this:

A::cB = new B;
As = new A[Number];

Then will the value of cB be the same across all instances?

I cannot pass the class pointer in the constructor as I need to create an array of instances. I tried this method but I get linker error.... unresolved external.

View 12 Replies View Related

C# :: How To Share Variables Between 3 Classes

Apr 2, 2014

I am wondering how to share a variable in 3 classes. For example:

variable class:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

[Code] ...

class that edits the variable:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication1

[code]......

The actual program:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication1

[code]......

What should happen when this runs is this:

Variable changed in program: 0
Same variable changed in a different class: 1

Instead, this happens:

Variable changed in program: 0
Same variable changed in a different class: 0

View 7 Replies View Related

C++ ::  How To Overload Variables In Derived Classes

Apr 6, 2013

Is it possible to overload a variable in a derived class? Example:

struct Circle
{
int radius() const { return r; }
private:
int r;
}
struct Smiley : Circle
{
// inherits the function int radius() const, but doesn't return Smiley::r
private:
int r;
}

View 7 Replies View Related

C++ :: Bit-checking Across Multiple Classes Private Variables

Oct 6, 2013

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 Related

C++ :: Changing Variables In Other Classes Code Blocks?

May 20, 2013

I want to make a basic RPG text based games with multiple classes. but I wan to know how In one class I make a variable and in another and can call the variable.

for exmaple

class2:
int hi = 1;
class1:
class2 a;
hi = 2;
cout << hi;
2

View 1 Replies View Related

C++ :: Segmentation Fault While Setting Classes Local Variables

Oct 12, 2014

When I set a local variable to a value it causes a segmentation fault. This happens in the GameObject class in the setGame method.

While your at it tell me what you think of the design. Am I on the right track? if not state why.

Here is the source: [URL]

View 6 Replies View Related

C++ :: Accessing Classes Member Variables Nested Inside Another Class

Feb 22, 2013

I have two classes, a Package class and a Person class. The Package class has two Person objects has member variables, a Sender and a Receiver. While overloading the << operator for the Package class so that it will make an output label from everything in the Package class. Here is my code...

class Package{
public:
Person Sender;
Person Reciever;
int weight;
double cost;
friend ostream &operator<<(ostream &out, Package &pack);

[Code] .....

So my problem is on that last output line, I am unable to call Sender.getName()... etc. Is there a proper syntax so that I can access the members of the Person class while overloading the << operator for the Package class?

View 2 Replies View Related

C++ :: Array Of Classes With Classes Inside

Oct 5, 2013

I have an array of (Student)classes created in Manager.h, which contains a new instance of class Name (name),(in Student.h)How would I go about accessing the SetFirstName method in Name.cpp if I was in a class Manager.cpp? I have tried using Students[i].name.SetFirstName("name");

// In Manager.h
#include"Student.h"
class Manager
{

[Code]....

View 2 Replies View Related

C++ :: How Do Two Classes Interact With Each Other

Aug 26, 2013

I want to know that how objects of two different classes interact with each other???

View 1 Replies View Related

C++ :: How To Know If Classes In Program Are Being Used

Aug 13, 2014

In this program the intention is to create a menu driven program for a pizza restaurant. I have to use a class called Pizza and have to include at least three public functions; one is called SetSize, another one is called Display, and the last one is called ComputePrice. A small pizza is worth $10, a medium is $14, and a large is $17. Each topping is worth 2 dollars. I know that the program runs correctly, but I have doubts over the classes and function actually being utilized correctly or at all.

Program:

#include <iostream>
#include <iomanip>
#include <cmath>
using namespace std;
class Pizza {
private:

int size;
int style;

[Code] .....

View 8 Replies View Related

C++ :: Using Multiset With Classes?

Oct 23, 2013

I'm trying to use multiset with a user defined class "edge". I'm trying to use the multiset as a priority queue, and I've created a "less<edge>" via operator<() overloading.

For some reason, I cannot insert edges into the multiset.

I understand that I might also have to create an "allocator". I got some ideas for creating it at [URL], but still don't know how to define size_type and difference_type.

Attached is my skeleton code, running on Windows 7 (32-bit), under Netbeans IDE, using Cygwin g++ 4.7.3.

How can I get this to work? What is important is that I get a priority queue working with my edges, prioritized by the weight.

#include <iostream>
#include <set> // for multiset
using namespace std; // assume std libraries (i.e. std::XXX)
class edge { // node, weight pair
public:

[Code].....

View 3 Replies View Related

C++ :: Derived Classes From DLL

May 5, 2013

I've created a base DLL for all my future DLL's, a way of getting version numbers and such and that compiles fine, but I can't add it into a class for a new DLL. All the headers do have an appropriate cpp to define the function declarations (and they compile fine).

All for the base DLL I have:

LibVer.h
Version.cpp
Function.cpp

LibVer.h

#pragma once
#include <vector>
#define DLLEXPORT 1
#define DLLIMPORT 2
#define DLL DLLIMPORT

[Code] .....

View 6 Replies View Related

C/C++ :: Get Volume Of A Box Using Classes

Feb 22, 2015

n the requirements it says this;

-create a get and set for height, width, length.
-A default parameterized constructor = 1
-A method to resize the box
-A method to get the volume of the box
-A method to convert the object to a string

My Questions:

The 3 parts I am confused by are the default parameter constructor, the re-size the box and the method to convert to string. For the default parameter part I figured making length, width and height = to 1 would work, but I'm pretty sure thats not what I'm supposed to do.

This is the main file

#include "box_class.h"
#include <iostream>
using namespace std;
int main() {
double length;
double width;
double height;
double volume;

[Code] ......

View 1 Replies View Related

C++ :: When To Use Static Classes

May 2, 2013

I am just wondering what the best practice is for when to use static classes (by static class, I mean a class which has only static attributes and functions).

If you are creating more than one independent object of a particular class, then obviously this should not be static because each object will be the same. But what about the case when you know that you will only ever need one instance of a class? On its own, does this mean that you should create it as a static class?

Personally, I use static class when I want its member attributes and functions to be available globally, which I think is fine. However, I am not sure about the case when I know that only one object will be created - should this be a static class or not?

View 1 Replies View Related

C++ :: Use Of Template Classes In Other Template Classes

Jan 24, 2012

I'm trying to make a template class which holds a template list I made. The list consists of template nodes (another template class I made).

My problem is that in some places (not everywhere) the compiler says that I'm trying to access private members of the node's class.

For example, if I define my node like this:
template<class T>
class CoefNode {
private:
T coef;

[Code]....

View 5 Replies View Related

C++ :: Nested Classes And Structs

Mar 12, 2014

I'm working on a project involving nested classes and structs like this:

Code: class A {
public:class B {
public:f()
{A::C* iCanDoThis; //no errors.
iCanAlsoDoThis->root->.... //this also works fine.}private:A::C* iCannotDoThis //this is what I would like to do.
Has errors
A* iCanAlsoDoThis;};private:struct C
{..data..};

C* root;};

Is it possible make a pointer to struct C a private member of class B?

View 1 Replies View Related

C++ :: Including Outside Functions Into Classes?

Mar 6, 2015

I have a hpp file with a list of inline finctions like this:

Code:
inline int check() {
return 1;
}
inline int check_1() {
return 1;
}

... What I would like to do is to include them into several unrelated classes. How can I do this. Can I just add the hpp inline functions in headers of my class containing files or not. I mean if they are not defined as class functions how can they be called. I don't understan the logic.

View 2 Replies View Related

C++ :: Export Classes In DLLs

Mar 6, 2015

Is there a way to export a c++ class for another language. I need to find an interpreted language that can use c++ classes (actually just one class) exported in DLLs. It wouldn't surprise me if you couldn't though because of how classes are handled in c++. Maybe python could do it because it's object oriented uses something very similar to the "this" pointer.

I have heard about something called COM.

View 7 Replies View Related

C++ :: Using STL Sort With Custom Classes?

Oct 8, 2013

I've written a doubly linked list per my assignment instructions. I've implemented begin() and end() iterators for it, and they work with no problems when traversing the list. However, I need to sort the elements in the list. We are allowed to use the sort function defined in the <algorithm> header since we haven't yet covered sorting algorithms.

But, I'm running into a ton of problems. I figured as long as the begin() and end() iterators were defined for the list, then sort(list.begin(), list.end(), compare) would do the trick. The main errors I'm getting are:

error: no type named iterator_category
error: no type named value_type
error: no type named difference_type
error: no type named pointer
error: no type named reference

And also errors for no match of the + and - operators for the iterator class.

I understand reference, pointer, and value_type, but I have no idea about iterator_category and difference_type. Additionally, I'm a little unsure why the + and - operators need to be overloaded.

View 8 Replies View Related

C++ :: Use Of Iterator Across Files And Classes

Nov 18, 2013

Here's a few parts of a program I'm working at. It does compile, and it does work as expected. Anyway Eclipse Kepler marks one line as a bug with the remark Field 'befehl' could not be resolved. The bug sign didn't show up when both classes were in one file.

ScriptInterpreter maintains and processes a vector of Objects, initialised with example data. An iterator of the vector keeps track of the current position while various methods process the data. I've copied the relevant lines only.

I can live with a few wrongly bug-marked lines in Eclipse. What I don't want is any hidden errors that express at some time later.

Is there anything wrong with the code? Anything that's not recommended and compiles anyway? Is anything c++11-specific about the questionable line?

AtomicCommand.h
class AtomicCommand {
public:
int befehl;

[Code] .....

Note that line 9 has a bug sign, too. Eclipse doesn't recognise all my c++11 code.

View 4 Replies View Related

C++ :: Constructors In Derived Classes

Apr 7, 2014

As long as no base class constructor takes any arguments, the derived class need not have any constructor, if one or more arguments are used then it is mandatory for the derived class to have a constructor and pass the arguments to base class constructors. While applying inheritance, we usually create objects using derived class. Then it makes sense for the derived class to pass arguments to the base class constructor. When both the base and derived class contain constructors ,the base class constructor is execute first.

In case of multiple inheritance, the base classes are constructed ,in the order in which they appear in the declaration of the derived class. Similarly in a multiple inheritance the constructors will be executed in order of inheritance. Since the derived class takes the responsibility to supply initial values to the base class,we supply the initial values that are required by all the classes together where the derived class object is declared.

The constructor of the derived class receives the entire list of values of arguments and pass them on to the base constructors int the order in which they are declared in the derived class

View 1 Replies View Related

C++ :: Storing Classes In Array

Sep 27, 2013

I have a base class Building. Then come its children classes - Commercial Building and Residential Building. The third level is composed of Apartment and House classes, both inherit from Residential Building.

I need to create an array of 20 elements that will store info about all these different types of buildings(Commercial Building,Residential Building,Apartment, House). How should I proceed?

View 5 Replies View Related

C++ :: Static Classes Vs Namespaces?

Jan 9, 2014

so i was trying to find out how to do unbuffered input in linux and came across this class: [URL] . i didnt like how i had to create a new instance of it each time i wanted to use it, so i made the functions static and renamed the class to Buffer. i could then call it like this: Buffer::On(); Buffer::Off();. My question is, when doing something like that where the class consists of two functions that can exist indepently of another, which is better: a class like what i did or wrapping it in a namespace?

View 3 Replies View Related

C++ :: Subtracting Value From 2 Integers In 2 Classes

Feb 11, 2013

I have 2 integers, both in 2 seperate classes in 2 seperate files. I have main.cpp, test_01.h, Test_01.cpp, Player.h and Player.cpp. I ahve a function which takes an integer (a) as a parameter (from Test_01.h and Test_01.cpp). a sets another integer (attackPower) from the same class equal to a. The integer (health) in the other class (Player.h and Player.cpp), is then equal to health -= attackPower. But instead of giving me the right answer 75 (health = 100 and a is set to 25 when i call the function) it gives me the answer.

main.cpp

#include <iostream>
#include "Test_01.h"
#include "Player.h"
using namespace std;
int main() {
Player p;
Test_01 t;

[Code] ....

View 2 Replies View Related

C++ :: Writing Some Classes Into A File

May 28, 2013

I want to write a program in cpp which will create a file and write some classes into it so that whenever i will execute that program i will have the auto generated file. How to do it....

View 1 Replies View Related







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