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
ADVERTISEMENT
Apr 24, 2015
HTML Code:
So I insert values from a vector into a list and into a multiset, and I noticed zero is added to their contents! I had to do a whole lot of debugging to find out where the error was, how can i stop this thing? Code which generates such error...
infact i checked the content of vector ups to be sure that there was no zero in it, but after loading into list combi_t * head, it seems like there was a zero added and this is giving me errors when i call function master_roller...
Code:
void ins(combi_t * &testa, int &numero, int &num, int &no)
{ // if (ricerca(testa, numero) == 0)
//{
combi_t *temp = new combi_t;
temp->val0 = numero;
temp->val1 = num;
temp->val2 = no;
temp->nextPtr = 0;
[Code] ....
View 2 Replies
View Related
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
Aug 26, 2013
I want to know that how objects of two different classes interact with each other???
View 1 Replies
View Related
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
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
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
View Related
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
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
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
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
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
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
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
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
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
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
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
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
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
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
Feb 28, 2013
How to solve this because i was not able to get the idea of using arrays in classes . Here is the Question :
The PVR Cinemas manager approaches you to develop a system for ticket booking. It has 5 screens each with a capacity of 500 seats of which 100 are platinum, 100 are diamond and 300 are gold. The cost of platinum, diamond and gold tickets are Rs.150, Rs.125, and Rs.100 respectively.
•Construct a class to model a screen with an array of integers for each category of seats. Provide a constructor to initialize the array to 0.
•Include a member function bookSeat() that gets the category of the seat and number of tickets to be booked and then prints the seat numbers. The booked seats are marked by 1. If no seats are available then your program should display appropriate message.
Test the above class with a main program that creates an array of objects (size of array depends on the number of screens) and display the total amount to be paid by the visitor.
View 6 Replies
View Related
Sep 15, 2013
I am currently trying to pass a matrix (multidimensional array) from my main into a function in a class. As usual, you have to include all array sizes, except the first. Unfortunately, the size saved under a variable. When I write it in the square brackets, it doesn't work.
Example:
//main
int main () {
int n = 5;
random object;
object.declare_variable(n);
int array [3][n];
object.pass_matrix(array);
[code].....
I also tried, putting the variable 'var' in the public section above the void and declaring it as static, but still there are error messages; fewer, in my case:
...not an integer constant
So what should I do? Id like to repeat that the int n will vary, which is why I can't just directly write down the size.
View 9 Replies
View Related
Oct 14, 2013
how would I pass this parameter and how/why is it not working this way? I've tried many different methods to this and I can't quite seem to figure it out.
studentList student;
student.push(252875, "Jerry", "UTPA");
What I thought would work
class student {
public:
int id; //student ID number
string name; //student’s name
string university; //student’ university
};
//student list is a doubly linked list of students.
[code]....
My header file.
I am honestly not sure where to start here. I would assume that it would know what to do with the varibles but it doesn't seem to want to accept them. It gives me
Error1error C2660: 'studentList::push' : function does not take 3 arguments
2IntelliSense: no suitable constructor exists to convert from "int" to "student"
View 11 Replies
View Related
Mar 1, 2013
I make a class (it stands for an ARMA time series), and I have a method wich modifies some of its variables. In other part of my program I have a function wich receives one object of this class as a parameter and, at some point, it calls the method of the ARMA class to modify it; here is my deal I want to pass the ARMA class by reference to this function, because I want the variables of the instance I'm passing to be modified, not those of a copy the method uses. Also, I would like not to declare the function inside the class ARMA, cause I use it in other places too (it's basically a Nelder-Mead optimization what it performs).
Here is a code wich sketches what I've been trying, and exactly the error message I get is "modifyParameter has not been declared".
#include <iostream>
#include <cstdlib>
using namespace std;
class ARMA{
[code]....
View 5 Replies
View Related
Feb 26, 2015
I have startes making a game where there is 3 ships that cross the screen verticaly, and the point is to shoot them down. So far I have actually managed to do this. I have also managed to add gamescore to the ships. But here is my problem, I cant find a way to combine the score from all three ships in to one score. I have all three ships in different classes, is that wrong? When I try to combine the scores, ship score1 cant see the other scores.
Do I need to somehow have all the ships in one class. Or are there a way to read the scores from three classes, and adding them up in to one in a new class?
One of the errors I get is "the name 'score1' does not exist in the current context.
View 14 Replies
View Related