C++ :: Vector With Own Class Not Working?

Aug 19, 2013

I have a settings class and a settingItem class. The settings class has a vector of settingItems. The vector is not working:

error C2065: 'settingItem' : undeclared identifier
error C2923: 'std::vector' : 'settingItem' is not a valid template type argument for parameter '_Ty'

with code line:

vector<settingItem> settings;

View 8 Replies


ADVERTISEMENT

C++ :: Accessing And Working With Vector From Multiple Threads

Oct 20, 2014

I have a vector that I would like to access and work with from multiple threads. I have created an example below to illustrate the functionality that I would like to accomplish.

The goals are to be (1) high speed, (2) thread safe, and (3) *if possible* continue to use vectors as my larger project uses vectors all over the place and as such I would like to maintain that.

However, if I need to switch from vectors to something else then I am open to that as well.

The following example below compiles but crashes rather quickly because it is not thread safe.

How I can fix the example below which I can then apply to my larger project?

#include <string>
#include <vector>
#include <ctime>
#include <thread>
#include <iostream>
#include <random>
#include <atomic>
#include <algorithm>
enum EmployeeType {

[Code] ....

View 1 Replies View Related

C++ :: Unexpected SIGSEG Abort When Working With Vector

Oct 9, 2013

I keep getting a segmentation error when ever I have the following code...

int main(void) {
//Section 1
unsigned long val = 12;
std::vector<unsigned long> vval;
for(unsigned long i = 0; i < 100; ++i) {
vval.push_back((unsigned long)0);

[Code] ....

Error: *** Error in `/home/alex/projects/bignum/build/bignum': free(): invalid pointer: 0x00007ffff75b5b88 ***
======= Backtrace: =========
/lib/x86_64-linux-gnu/libc.so.6(+0x80a46)[0x7ffff7274a46]

compiler is clang++ 3.2

It doesn't happen if I restructure it so that bignum::num is not a pointer to an std::vector<unsigned long>

View 10 Replies View Related

C++ :: Create Class Vector As Template And Define Operations On Vector?

May 13, 2013

I need to create a class vector as a template and define operations on vectors.

And this is what I made.

#include<iostream>
using namespace std;
template<class T>

[Code].....

View 2 Replies View Related

Visual C++ :: Tooltips Not Working For All Controls In CFormView Derived Class

Sep 16, 2014

I can't get tooltips to show up for the windows I want in my CFormView derived class. I have copied the code from the MSDN entry on EnableToolTips(). But only two windows respond with a tooltip:

CONTROL "Tree1",IDC_TESTPLANS,"SysTreeView32",TVS_HASBUTTONS | TVS_HASLINES | TVS_EDITLABELS | TVS_SHOWSELALWAYS | WS_BORDER | WS_HSCROLL | WS_TABSTOP,1,36,85,91
CONTROL "Tab1",IDC_TABCMD,"SysTabControl32",0x0,101,0,239,181

Other windows do not respond. For these windows my function designed to catch the TTN_NEEDTEXTW and TTN_NEEDTEXTA messages is not called. Windows such as

LISTBOX IDC_TESTPLANNAMES,0,119,48,40,LBS_SORT | LBS_NOINTEGRALHEIGHT | WS_VSCROLL | WS_TABSTOP
PUSHBUTTON "",IDC_BTN_COPY,105,177,24,24,BS_ICON

Why wouldn't the messages be sent for those windows? I'm using the code

ON_NOTIFY_EX_RANGE(TTN_NEEDTEXTW, 0, 0xFFFF, &CCntlrView::OnTtnNeedText)
ON_NOTIFY_EX_RANGE(TTN_NEEDTEXTA, 0, 0xFFFF, &CCntlrView::OnTtnNeedText)

(CCntrlView is the name of my class derived from CFormView.) And as I pointed out, I'm using the code straight from the example given in MSDN for CWnd::EnableToolTips(), with the only difference being that all my controls are created in the rc file as shown above.

View 12 Replies View Related

C++ :: Passing Vector Of Class To Function Of Another Class?

Dec 14, 2014

im passing a vector of a class to a function of another class. But i cant access the data on the classes inside the vector.

Something like that:

class CDummy{
...
public:
string m_name;

[Code].....

Im creating the vector on main() and using push_back with a pointer to an initialized CDummy instance

View 5 Replies View Related

C++ ::  Class Safe Array Type Print Function Not Working When Called

Oct 22, 2013

I've created a function where you can choose any bounds for an array based list (positive or negative, as long as the first position is smaller than the last position). However for some reason when I call the print() function in my application program it doesn't do anything. My print function is technically correct (I still have work to do on the output) but I can't figure out why it wont show anything at all. Below is my header, implementation, and main program files, along with results from running the program.

Header File:

//safearrayType Header File
class safeArrayType {
public:
void print() const;
void insertAt(int location, const int& insertItem);
safeArrayType(int firstPlace=0, int maxPlace = 100);

[Code] ....

ResultsEnter the first bound of yourlist: -3(this was my input)
Enter the last bound of yourlist: 7(this was my input)

Press any key to continue...

View 1 Replies View Related

C++ :: Creating Own Vector Class?

Nov 15, 2014

I was trying to implement own vector class and wrote some code. Below is the code.

Code: #include<iostream>
#include<vector>
using namespace std;
template <typename T> class MyVector
{
T *mem;
int m_size,final_size;
public:
MyVector() : final_size(1),m_size(4)
{

[code].....

I have question on this function.

Code: myVecPush_back(T t){}

Here I was able to put elements upto any number of time, but I have allocated memory to only 4 elements in T *mem.

My question, why the program is not crashing when I tried to put elements more that 4?

Is since the variable is of type Template? Any specific reason for this?

View 2 Replies View Related

C++ :: Custom Vector Class

Oct 9, 2014

Let's say we have a custom Vector class and I need to know which of the following is considered to be more efficient and why of course.

Vector Vector::operator+(const Vector &b) const {
return Vector(x+b.x,y+b.y);
}

Vector Vector::operator+(const Vector &b) const {
Vector tmp(x+b.x,y+b.y);
return tmp;
}

View 1 Replies View Related

C++ :: Define A Vector In A Class?

Aug 9, 2013

First this is my code:

#include <iostream>
#include <vector>
#include <cstdlib>

[Code].....

the blacked content got problems: the error messages are the throat_t::P or throat_t::T is inaccessible.

View 3 Replies View Related

C++ :: Vector Is Different For Every Class Instance

Feb 12, 2014

Okay so I have a class Student, which takes a number and a vector as a parameter for the constructor. Everything works well, until I output the values of the vector for every instance. The problem is that the same vector is being shared with EVERY instance I create, but I want it to be unique for every single one!

//Student.h
#ifndef __Grade_calculator__Student__
#define __Grade_calculator__Student__
#include <iostream>

[Code].....

View 1 Replies View Related

C++ :: Class Objects In A Vector?

Mar 16, 2013

So I'm trying to store class objects in a vector:

#include <iostream>
#include <fstream>
#include <sstream>
#include <string>

[Code]....

1. Am I storing it correctly?
2. How would I access the stored data, say, if I wanted to compare it to other stored data or COUT it?

View 1 Replies View Related

C++ :: Constructing A Vector In A Class

Jun 15, 2012

What I want to do with the below code is to construct the vector containing 'Ability' objects in the class 'Card'. I have searched for the solution in the past, and have been unsuccessful, mainly because the vector contains child classes of the parent class 'Ability'. The below code is a snippet of the larger program that I am working on, and should compile:

main:

Code:
#include <cstdlib>
#include <iostream>
#include <vector>
#include <string>
using namespace std;
#ifndef _abilities_h_

[Code] ....

As you can see, in the class 'Card' I have a pretty large constructor. Up to this point, however, I have failed in my attempts to construct the abilities vector, because it contains those child classes.

View 7 Replies View Related

C++ :: How To Read CSV File With Own Vector Class

Jul 7, 2014

Input file:

Course Of Sales.csv
Time,Price ($),Volume,Value ($),Condition
10/10/2013 04:57:27 PM,5.81,5000,29050.00,LT XT
10/10/2013 04:48:05 PM,5.81,62728,364449.68,SX XT
10/10/2013 04:10:33 PM,.00,0,.00,

How to read the csv file with my own vector class. I already have date.h,date.cpp,time.h,time.cpp

How to do the maintest and how to create the vector class

I need to show Date, highest price and Start time(s) of the highest share price

View 3 Replies View Related

C++ :: How To Loop Through A Vector Of Class Objects

Mar 22, 2013

For a beginners C++ lab, I have a base class Employee and two derived classes HourlyEmployee and SalaryEmployee. In main, I have a vector defined as vector <Employee *> VEmp; It's then passed to a function to get the input, which works fine. But what I'm struggling with is another function with the header "printList(const vector <Employee *> & Ve)". It's supposed to loop through the vector and call the appropriate printPay function, which is a seperate print function inside each derived class. How do I loop through the vector and print it out? I was trying to do a for loop and something like "Ve[i].printPay();", but that doesn't work. So how would I do it?

Here's some snippets of the relevant code.

class Employee {
....
virtual void printPay() = 0;
};
class HourlyEmployee : public Employee {

[Code] ....

View 4 Replies View Related

C++ :: 2 Dimensional Vector Represented As A Class

Nov 5, 2014

I have to create a class to represent a 2 dimensional vector. I need to include certain member functions such as a function to find magnitude of the vector, and one to find the dot product of that vector with another vector, and several others too. That's all fine. A stipulation of the problem is that I must include a constructor which can take cartesian form of the vector and a constructor which can take polar form of vector. Since this involves overloading the constructor the best solution I have come up with is to create the object with either doubles or floats so that the compiler can choose the correct constructor. This seems like a really bad idea. Is there a way I can get the compiler to choose the correct constructor without doing it using the precision? Here is a sample of my header file, there are many more member functions

class Vector{
public:
Vector(double x, double y, double v, double w){
myArray[0]=x;
myArray[1]=y;
additionalArray[0]=v;
additionalArray[1]=w;

[Code] .....

In my .cpp file the object is created with either four doubles or four floats depending on which constructor I want to implement. There must be a better way. Additional Array is created for use in member function which require calculations with a second 2d vector.

View 1 Replies View Related

C++ :: Vector Of Pointers - Abstract Class

May 13, 2014

I need to create a vector of pointers and hold the book objects in it. then i have a virtual function in my books which is a pure virtual in LibraryItems. When i try to add the books object in my code, i understand that since the scope runs out there is no object that is added. so when i run print it gives me an error.

#include<iostream>
#include "books.h"
#include "library.h"
#include <vector>
using namespace std;

int main(int argc, char * argv[]) {
vector<LibraryItems* >libraryInfo;

[Code] .....

View 4 Replies View Related

C++ :: Vector As Private Class Member

Feb 16, 2013

I get a problem with the vector as a private class member: When I did't initialize the vector in constructor(which means the size of the vector would be 0), I used a class function to add two elements to the vector and it worked (because I added a "printf" to output the size of the vector and the elements within that function). However, when I used another class function to visit that vector, no element was in and the size became 0.

Then I tried to add two elements to the vector during the construction, and it turned out that these two elements could be stored in the vector while other elements added through class functions could not.

I guess there may be some problems on the scope of the function. But I feel the class member should not be effected by the scope of the class function.

View 7 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++ :: Class With A Vector Of Objects As Attribute

Dec 9, 2013

I'm having the same problem : [URL] .....

Though, my vector isn't one of int, it is a vector of objects from another class and NetBeans won't compile it.

#include <cstdlib>
#include<vector>
#include <string>
#include<iostream>
using namespace std;
class estoque{

[Code] .....

View 3 Replies View Related

C++ :: How To Initialize Vector In A Class Object

Mar 6, 2013

I want to make a class, named generation, having a vector<chromosome> type data member.

chromosome is also class name.

chromosome has a 'route' as data member, which type is class TArrayI defined in ROOT package.

the size of route is to be fixed according to parameters of generation class object.

class chromosome{
public: chromosome(){;}
....
protected:
TArrayI route;
};
class generation{
public: generation(int PopSize=300, int numCity = 36){
.........
}
vector<chromosome> Population;
};

I want each element, chromosome of Population, to have a numCity size of route.

View 2 Replies View Related

C/C++ :: Vector As A Member Data Of Class

Dec 30, 2013

If I want a class with a vector data member, can I specify it as follows?

std::vector< bool > integers( 101 )

I'm having some problems when compiling code.

View 3 Replies View Related

C++ :: How To Change 2 Dynamic Array Int Vector Class

Oct 29, 2014

// dynamic memory for 2D char array
char **board = (char**) calloc(column, sizeof(char*));
for(int i=0; i<column; i++)
board[i] = (char*) calloc(row, sizeof(char));
//for char 255 row and colum
char temp[255];
inputFile.getline(temp,255);

[Code]...

so i want to change into vector class like Vector<board>row;

View 8 Replies View Related

C++ :: Adding Items From File To Vector Of Class

Oct 10, 2013

how to add a list of information from a file to a vector of a class. Here is my code:

Champion_Info.h
#ifndef CHAMPION_INFO_H_INCLUDED
#define CHAMPION_INFO_H_INCLUDED
#include <vector>
#include <string>

[Code].....

View 6 Replies View Related

C++ :: Making List Of Champions - Vector Of Class

Oct 6, 2013

I am making a simple program that is suppose to make a list of champions and their items from the game League of Legends. I am stuck on making a vector of the class so each slot within the vector would hold each champion and its data. This is what I got:

Champion_Info.h

#ifndef CHAMPION_INFO_H_INCLUDED
#define CHAMPION_INFO_H_INCLUDED
#include <vector>
#include <string>
using namespace std;
class Champ_Info

[Code] ....

View 3 Replies View Related

C++ :: Adding Additional Functions To STL Vector Class

Jan 30, 2013

How would I add my own function to the vector class?

View 3 Replies View Related







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