C++ :: Access Enum Class And Its Values Outside Of The Class

Apr 23, 2013

I cannot wrap my head as to how to access my enum class Azimuth.

Code: #ifndef BOUSOLE_H
#define BOUSOLE_H
#include <iostream>
#include <string>
#include "StringHandler.h"
class Bousole{

[code]...

And here is where I am trying to access my enum for testing/understanding purposes

Code: #include "Bousole.h"
using namespace std;
int main (int argc, char *argv[]){
cout <<"Start bousole" << endl;
Bousole b;

[Code] ....

View 6 Replies


ADVERTISEMENT

C++ :: Class With Enum And Constructor

May 29, 2013

I really confused with constructor (default constructor and constructor with parameters)

I coded this problem

and I worked almost, but I stock in constructor

Code:
class Tier {
public:
enum TIER_MAKE

[Code] ....

This is tier class and I have to finish constructor in class car (for simple, I skip detail code) -red things are the parts from class Tier

Code: Car()
: make(NULL), passengers(0), fuelcap(0.0), efficiency(0.0), tier(Tier::nexen)
{ }

[Code] ....

And someone said default constructor part has to be this

Code:
car( Tier::TIER_MAKE p_tiermaker = Tier::nexen )

//after i skip
but default constructor should be no parameter...? isn't it?

View 1 Replies View Related

C++ ::  Using Enum Defined In Class

Apr 1, 2013

I am trying to write a game in C++ with SDL, and I have a class that allows me to handle events. The class is actually really simple: It takes the SDL_Event, then 2 variables from 2 different enum to determine for which Event and which Key should be checked, and then a variable that will be modified if the event happens. Here is the class

EventParser.h
#include "SDL.h"
#include "SDL_opengl.h"
template<class T>

[Code]...

As of yet the variable only changes if the Left key has been released, it will be extended if the error has been solved.

Then, in my main.cpp file I define the Event and the EventParser as

SDL_Event event;
EventParser<float> ep;

And in a loop, the parseEvent function is called like this:
ep.parseEvent(event, ep.KeyUp, ep.LEFT, &xVariable);

However I get a linker error (not the first one I got when programming this game)
error LNK2019: unresolved external symbol "public: void __thiscall EventParser<float>::parseEvent(union SDL_Event,enum EventParser<float>::EventType,enum EventParser<float>::KbdKey,float *)" (?parseEvent@?$EventParser@M@@QAEXTSDL_Event@@W4EventType@1@W4KbdKey@1@PAM@Z) referenced in function _SDL_mainC:UsersPrideRageDocumentsVisual Studio 2012ProjectsSDL_TestSDL_Testmain.objSDL_Template

View 6 Replies View Related

C++ :: Cannot Access Private Member Declared In One Class But Can In Another Class

Sep 4, 2014

So I have an ImageManager class, Board class, and Box class. In Board.h I can declare ImageManager imgr; and in Board's constructor I can use imgr and its functions and such. However, in Box.h when I try and declare ImageManager imgr; I get the error "cannot access member declared in class ImageManager". Both declarations are under private, and exactly the same, but one doesn't work. Also, is there a way to only have one instance of ImageManager?

View 19 Replies View Related

Visual C++ :: Access Variable Inside Class From Other Class

Nov 9, 2013

I am trying to access a variable from another class through another class but it is not returning its "instance"?

Example:
Class View

Code:
...
V3D_Viewer viewer;
...
Class MainWindow

Code:
...
viewer* myView;
myView = new viewer();
...
Class Test

Code:
...
MainWindow window;
window.myView->setBackgroundColor(WHITE);
...

I am new to c++ references and pointers,

View 3 Replies View Related

C++ :: Transfer Values Set In Privates Of Base Class By Object Of One Derived Class To Another

Apr 26, 2014

I have my main.cpp like this:

#include <iostream>
#include "curve1.h"
#include "curve2.h"
using namespace std;
int main() {
Curve1 curve1Obj;
Curve2 curve2Obj;

[Code]...

Base class Score has two derived classes Curve1 and Curve2. There are two curve() functions, one is in Curve1 and other in Curve2 classes. getSize() returns the value of iSize.

My base class header score.h looks like this:

#ifndef SCORE_H
#define SCORE_H
class Score {
private:
int *ipScore;
float fAverage;
int iSize;

[Code]...

You can see that I have used curve1Obj to enter scores, calculate average and output. So if I call getSize() function with cuve1Obj, it gives the right size that I took from user in enterScores() function. Also the result is same if I call getSize() in score.cpp definition file in any of the functions (obviously).
.....

The problem is when I call curve() function of Curve2 class in main (line 23) with the object curve2Obj, it creates a new set of ipScore, fAverage and iSize (i think?) with garbage values. So when I call getSize() in curve() definition in curve2.cpp, it outputs the garbage. .....

How can I cause it to return the old values that are set in curve1.cpp?

Here is my curve2.cpp

#include <iostream>
#include "curve2.h"
using namespace std;
void Curve2::curve() {
cout << "getSize() returns: " << getSize() << endl; // out comes the garbage
}

Can I use a function to simply put values from old to new variables? If yes then how?

View 3 Replies View Related

C++ :: Access Private Data Of Base Class Without Access Modifier

Sep 9, 2013

if we don't provide the acces modifiers for base class and we need to manipulate the private data of base class in derived class. Is there anyway to acces the private data members? Here's a coding example

class A {
private :
int a;
};
class B : public class A {
public :
void displayA() { cout<<a<<endl; }
};

how i can acces the a of base class A in derived class B without acces modifiers.

View 16 Replies View Related

C++ :: Using A String / Enum To Access Int Matrix?

Apr 2, 2012

Any way to use a string to access a specific item in a matrix of int[X].

I have a program which uses enums as iterators to reference a large amount of data. To select an item in the matrix, the user will enter a string, which is also an enum, which also must serve as an iterator for something in the matrix. Here is a toybox example:

#include <iostream>
#include <string>
using namespace std;
enum NyNumbers { First, Second, Third, Forth, LAST_VALUE };
int main(int argc, char* argv[]) {
int Matrix[LAST_VALUE] = { 1, 3, 7, 12 };

[Code] .....

The idea is the user executes the program by typing "./RUN First" to print out the first element in the MyNumbers array, "./RUN Second" to access the second, and so on. I can't use static numbers for the iterator. (i.e., "./RUN 1") I must reference by enum/string.

When run, the output of this problem is thus:

====================================================================
user@debian$ ./RUN Second
Matrix[ atoi(Second) ]: 1
user@debian$
====================================================================

BTW, if I change line 12 to this

====================================================================
cout<<Matrix[ argv[1] ]<<"
";
====================================================================

The error message is this

====================================================================
user@debian$ make
g++ -g -Wall -ansi -pg -D_DEBUG_ Main.cpp -o exe
Main.cpp: In function `int main(int, char**)':
Main.cpp:12: error: invalid types `int[4][char*]' for array subscript
make: *** [exe] Error 1
user@debian$
====================================================================

Which isn't unexpected. How to input the enum as argv[1]?

View 2 Replies View Related

C++ :: Invoke Enum Class From Header File To Cpp File

May 21, 2014

I have been working a project in C++. I have TTTMain.cpp file that has all the function calls, TTTFuntions.cpp that has all the functions, I have TTT.h file that has all the prototypes and variables and additionally I have Winner.h that has enum class Winner declaration in it. Here is my block of codes:

Winner.h file:

#ifndef winner
#define winner
enum class Winner {

[Code]....

My question is when I compile this gives me error on

Winner gameSquares[] = { Empty, Empty,Empty, Empty, Empty, Empty, Empty, Empty, Empty };

with saying "invalid use of non-static data data member" and It says "Empty was not declared in this scope."

I know calling enum is very very trick.

View 3 Replies View Related

C++ :: Can't Access A Function In Other Class

Nov 24, 2014

I am essentially trying to get a value from a 'Matrix' that is created. Using a function in the class where the matrix is created. But when trying to do this I get the error: Call to non-static member function without an object argument in this line when trying to call the function:

Matrix::get(sizeR, sizeC);

View 6 Replies View Related

C++ :: How To Access Variable In Different Class

Oct 22, 2014

how can I make the queue of type pcb

and how to access pid in other clases?

View 6 Replies View Related

C/C++ :: How To Access Field Of A Class By Name

May 2, 2012

class myCls{
int x;
};

and then I create:

myCls c1;

and now:

is there way that I go like: cout << c1;
not overloading << operator;
and it shows me a value of c1.x?
just wanna replace c1 with that value;
I need sth similar to indexer from c#.

View 1 Replies View Related

C++ :: How To Access Pointer To Class Member

Jan 10, 2015

I have the following scenario :

Code:
class test {
public :
int num;
};
int main() {
test t1;
test *ptr = &t1;
int test :: *mem_ptr = &test::num;
}

I need to access mem_ptr (pointer to a class member) through :

a. object (t1)

b. pointer to the object (ptr).

How can i do that ?

View 4 Replies View Related

C++ :: Access Another Library (DLL) Which Has Same Class Name And Method Name

May 27, 2013

I have 2 c++ libraries called "Lib1" and "Lib2". Both libraries have same class called "Total.h and Total.cpp"

I want to access lib1 class in lib2. since it has same class (i.e same header file), i couldn't refer lib1's members in lib2.

Lib 1 :

Total.h :
class Total {
public:
static void Test(double);

[Code] .....

How to access another library which has same name and how to add header file ?

View 1 Replies View Related

C++ :: Access To Private Member Map Outside Class

Oct 24, 2013

This question is more from a design point-of-view rather than coding it to be a fully functional.

So here it goes:

I have multiple files which each require their own object of same class type (ref. First Class). File contents are read from a file to a unordered_map<std::string, std::vector<std::string>> which is either private or protected member inside First Class. First Class does not need any public functions to add, remove or change the data during runtime, but changes are only being made by checking if the file size has changed during the day, if the size is not equal to the last check, map gets updated.

Now, I have a Second Class which is a data handler class. It has public member functions with arguments that needs to be get from First Class's unordered_map using const_iterator. Which way to go with design and implementation.

I know there's two methods to do this. Re-doing handler class is also not out of the question. These two methods I'm aware of are:

1. Declare these maps to local scope, build few global functions and here we go. (Probably the easiest way.)

2. Create public member functions to a First Class which either return a pointer or a reference to a protected/private member. (I'm under the impression that I really shouldn't be doing this because of a bad coding practice.)

Note that I don't need any code here, just some other point-of-views regarding the subject itself for learning better coding practices.

View 5 Replies View Related

C++ :: Class Data Member Access?

Jul 5, 2013

I have some doubt regarding class data member accessing in another file.Follwing code showing error.

class A://file a.cpp
{
public:
int add;
int sub;
};
//file b.cpp
extern class A
void cal()
{
A::add=A::sub;
}

View 4 Replies View Related

C++ :: How To Access Virtual Base Class

May 4, 2013

How can I access the virtual base class? This is a practice exercise from c++ primer plus 6.

The problem is that the name becomes No Name instead of the name specified when creating the gunslinger, I don't know how I can call the virtual base class explicitly

Output,

#ifndef PERSON_H_
#define PERSON_H_
#include <string>
#include <iostream>
#include <cstdlib>
using std::string;
class person

[code]....

View 7 Replies View Related

C++ :: Get Access To Functions Of A Derived Class

Jul 11, 2013

I have a big problem with searching a solution for getting access on getters and setters of the derived classes of an interface.

Interface:

class IfParam
{
public:
IfParam();
};

Now I have a derived class for each needed datatype. E.g.

class Int32Param: public IfParam
{
public:
Int32Param();
Int32Param(IfParam* l_param);
int getValue();
void setValue(int l_value);
private:

[Code]...

My Problem now ist getting access to the getters/setters over the interface. I wish I could initialize the Params like this:

IfParam* param = new Int32Param();
param.setValue(12);

IfParam* param = new StringParam();
param.setValue("String");

But to have access to the getter/setter I have to declaire the functions in the interface as generic functions. But how? I tried to use temlates, but then i have to declaire IfParam as IfParam<int>. Thats a problem because in my original program I do not know which TypeParam the IfParam interface will be initialized with when I create the pointer.

View 7 Replies View Related

C# :: How To Access Form Method From Another Class

Jan 7, 2015

Basically am trying to reference a method in a my Form1 class into another class. So far I have tried multiple different methods to try and access the method but have not managed it so far. Both classes use the same namespace. The part of my form class that I am using are as follows:

public class Form1 : Form
{
IContainer components = null;
private ButtonPanelThread p1, p3, p4;

[Code]....

View 4 Replies View Related

C# :: Unable To Access List Class

Mar 3, 2015

how would i access the list created,i should be able to access the list from all other class, adding to it update ect ect.

class test2
{
public string FirstName{ set; get; }
public string LastName { set; get; }
public string Location{ set; get; }
private List<test2> myList = new List<test2>();
public override string ToString()

[code]....

now in a seperate class how would i view the item (print in console) and edit 'mike' location to XYZ.

View 6 Replies View Related

C++ :: Access Other Members Within Same Nested Class?

Jul 12, 2013

It's hard to give a precise title but here is the question in detail: I have a class, something like this:

Code:
class classA{
public:
void fnA();
...
};

and another class that contains objects of classA:

Code:
class classB{
public:
classA A1;
classA A2;
classA A3;
vector<classA*> vA;
...
};
classB B1;

Now is it possible to access B1.vA from B1.A1.fnA() through some kind of pointer chain like this->parent->vA ? If so

View 7 Replies View Related

C++ :: Cannot Access Private Member Declared In Class

Aug 22, 2013

I have a method:

int filetodb(std::wstring szwf, SQLHANDLESTR *h);

I want to use it, in a thread.

std says, use thread, as:

std::thread second (bar,0); // spawn new thread that calls bar(0)

How can I do this, for my method, that uses more than one, i.e., two, parameters?

My code is:

std::thread thread = std::thread(filetodb, filesP->at(i), h);

compiler says:

Error10error C2248: 'std::thread::thread' : cannot access private member declared in class 'std::thread'c:program files (x86)microsoft visual studio 11.0vcincludexmemory06061ConsoleApplicationa

How, can I do this?

View 2 Replies View Related

C++ :: Nested Class Vector Index Access?

Mar 22, 2014

Is it possible to pass the vector index '4' to the Height() function without passing it as a parameter of the function.

Basically, I'm trying to eliminate using 4 twice... what I'd LIKE the statement below to look like is this:

gx.Cell[4].Height();

The only way I can figure out how to get it to work is like this...

class grid{
public:
class CELL{
public:
int Height(int index); //returns the height of this cell

[Code] .....

View 8 Replies View Related

C/C++ :: Limit Access To Class Member Functions

Feb 28, 2014

Suppose I make a class, something like having the constructor being invoked first makes sense, I don't have a problem with that. But, how could I limit access to functions until certain functions are called? Perhaps this isn't built into the language so you can't. And maybe this problem never comes up. For example if you have a set() and get() functions, if they are both public functions, there doesn't seem to be a way for the compiler at least now if set() never gets called you shouldn't call get(). I just see this as error prone if you need to use libraries, you have to know not to do it from documentation instead of something the compiler can check.

View 11 Replies View Related

C++ :: Cannot Access Protected Members Of Parent Class

Oct 22, 2014

I am doing C++ data structures exercises, and I am still learning some of the more basic concepts. I have a parent class:

template<class T>
class linkedListType {
public:
protected:
int count;
nodeType<T> *first;
nodeType<T> *last;
private:
};

Derived class:

#include "linkedListType.h"
template<class T>
class orderedLinkedList: public linkedListType<T> {
public:
void mergeList(orderedLinkedList<T> &list1, orderedLinkedList<t> &list2) {
first = list1.first;
...
} private:
};

There is more code in my mergeList() function, but I included the line that is giving me problems. The error that my CodeBlocks compiler is giving me is that 'first' was not declared in this scope.

Strangely enough, if I change it to this->first, the error disappears.

1. Why does it not recognise 'first'?
2. Why would this->first work at all? Is the 'this' object a smart pointer?

View 1 Replies View Related

C/C++ :: Setting Signal Handler - How To Access Class Member

Dec 4, 2014

I need to set signal handler for my process. As the signal is related with the process on system level I have faced the problem. My program consists several classes. They are connected together. But it doesn't metter in this case. The problem is that I need to access to member and methods of the class from my signal handler. For instance , I have class named Foo at it has some members and methods.

So from my handler I need to call its function and change members. I understand that compiler should know that this class instances will exist during all program execution. I have tried to set static member class Foo instance in another class , but this didn't solve the problem. How to correctly implement signal handling in such case.

Here is example of my code

class MyContainer {
private:
std::vector<Foo> container;
public:
int removeFromContainer(Foo* aFoo) {

[Code] ....

View 1 Replies View Related







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