C++ :: How To Define A Class Which Have Two Members

Sep 16, 2013

I want to define a class, which will have two members, for example, vaporPressureStatus and vaporPressure

enum vpStatus_t {nonesense, unknown, known, saturated};
class pore_t {
public:
vpStatus_t vpStatus;
double vaporPressure;
};

when vpStatus is nonsense and unknown, the vaporPressure should not have a value; and if I calculate out a value for vaporPressure, the vpStatus can be set as known.

I am wondering if there is any set, pair or other structure can hold this two members together, so that when I change one's value, the other guy will also change accordingly.

View 3 Replies


ADVERTISEMENT

C++ :: Friendship From Derived Class Method To Base Class Members

Jul 15, 2014

I would like to know if there's a way to make a method from a derived class a friend of its base class. Something like:

class Derived;
class Base {
int i, j;
friend void Derived::f();
protected:
Base();

[Code] ......

View 3 Replies View Related

C++ :: Define A Class That Only Inherits From Parent Class And Takes One Argument

Jan 5, 2015

In the project I'm currently working on I define a class that only inherits from a parent class and takes one argument.

Does this class need to be defined in the header or source file? I read different answers around the internet.

Or is it better to always split definition and logica, even for something like an operator?

View 1 Replies View Related

C++ :: Set And Get The Value Of Different Members In A Class

Jun 28, 2013

I am new to c++ programming and i have written a simple class program to display the name and duration of the project

#include<iostream>
class project {
public:
std::string name;
int duration;
};

[Code] ....

Now i am trying to the write the same program with the usage of member functions using set and get member functions. i have tried the following

#include<iostream.h>
class project {
std::string name;
int duration;
// Member functions declaration

[Code] ....

I am not sure whether above code logic is correct, how to proceed with it.

View 3 Replies View Related

C++ :: How Do API Call Back To Class Members

Jun 24, 2014

I've been creating an API and I'm now stuck on callbacks. There are many APIs that allow callbacks to class members(e.g. Windows API) using a void pointer to the object. I've searched the internet for hours and I can't find one example of how to use the "hidden object parameter" of an class method pointer that doesn't use std::function/bind or boost::function/bind. Any information on how API's like Windows API are able to use class methods as callbacks

View 6 Replies View Related

C++ :: Why Class Members Private By Default

Apr 14, 2013

The reason that class members are private by default is because, in general, an object of a class should be a self-contained entity such that the data that make the object what it is should be encapsulated and only changed under controlled circumstances. Public data members should be very much the exception. As you’ll see a little later in the chapter, though, it’s also possible to place other restrictions on the accessibility of members of a class.

View 17 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++ :: 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++ :: Define A Class For A Type

Apr 29, 2014

Define a class for a type called CounterType. An object of this type is used to count things, so it records a count that is a non-negative whole number.

Include a mutator function that sets the counter to a count given as an argument. Include member functions to increase the count by one and to decrease the count by one. Be sure that no member function allows the value of the counter to become negative.Also, include a member function that returns the current count value and one that outputs the count. Embed your class definition in a test program and run sufficient tests to verify it all works correctly.

View 1 Replies View Related

C++ :: Accessing Private Members From Inside Class

Jan 10, 2013

Let's say I have the following class:

class MyClass {
private:
int m_myInt;
public:
int myInt() {return this->m_myInt;};
int myFunc();
};

Which of the following is to prefer;

int MyClass::myFunc() {
return 2*this->m_myInt;
}
or
int MyClass::myFunc() {
return 2*this->myInt();
}

The second one seems better? Are both OK? What's the best practice?

View 13 Replies View Related

C++ :: Const Static Members In A Template Class?

Jan 17, 2013

I have a little problem with template classes and their specialization. Here is a short example:

template <typename T>
struct A{
// some typedefs

[Code]....

The above example is not compiling, because of the assignment of the const static double. Double needs a constructor, but that doesn't work (or seems not to work) with static.

I'm not sure, if it works at all in C++ that way. All I want is a template struct with some typedefs and a constant which is different for different specializations. Don't think it has to be static, but that would be better style, wouldn't it?

View 3 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++ :: How To Put File Data Into Members Of A Class - Array Transferring

Mar 10, 2013

I'm trying to put file data into members of a class. Remember to type in the file name you want to open. Cool feature right? I just had Dbase.txt so I chose that.

Fixed stuff in the .txt. Now I need to figure out why it only does 1 set and then ends.

#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <fstream>
using namespace std;
class INFO {

[Code] .....

Dbase.txt:
Bob
Guy
Programmer
M
9999.99
40
------------------
Little
Guy
Little Brother
M
0.0
3
------------------

View 14 Replies View Related

C++ :: Storing A Class With String Members Into Binary Files

Nov 17, 2014

Im trying to make a c++ program for a school project, and i need to store the information into binary files, but I'm having some problems trying to store a class with string members, for example:

class whatever{
protected:
string name;
public:
(List of functions)
}

But if I do that, my code just dont work when I write and read a binary file, but if I change the string to char array, for example:

class whatever{
protected:
char name[20];
public:
(List of functions)
}

It works good, so I wanted to know if there's some way to store a class wiht strings in binary files, or what am I doing wrong?

View 4 Replies View Related

C++ ::  Storing Static Class Members Of Dynamic Variable Type In DLL

Oct 15, 2013

How I can implement it.

Tickable.h

#include <list>
#ifdef TICKABLE_EXPORTS //Automatically defined by MSVS
#define DLL __declspec(dllexport)
#else
#define DLL __declspec(dllimport)
#pragma comment(lib, "Tickable.lib")
#endif

class DLL Tickable{

[Code] ....

error LNK2001:
unresolved external symbol "private: static class std::list<class Tickable*,SKIPPED BITS> Tickable::subs" HUGE_SYMBOL_LIST
PATHTickable.obj

I know with such a tiny and insignificant class the dll export seems pointless but this class is actually intended to be a .lib ONLY. But it is derived from by .dll style classes, and through inheritance this error is the exact same as what appears in the derived class, I just imagine that the cut down version would be easier to work with.

Is it possible to hold either a static variable in a dll which is of a dynamic type, OR would it be possible to reference an external variable which is static throughout the instances and this variable can be chucked away in a namespace of mine somewhere?

I suppose my only other option (if this is possible) would be to define a maximum instance number and create a standard array of pointers but this could both waste so much memory when not in use and cause problems if I need more memory.

View 5 Replies View Related

C++ :: Cannot Define Method Of Inner Nested Class If It Is Private

Jan 16, 2013

it seems that I cannot define a method of an inner nested class if it is a private class. for example:

class outter {
class nested {
void foo ( void ) {} // okay - but is this inline?
} void inner::foo( void ) {} // not okay - cannot define inside another class
} void outter::inner::foo( void ) {} // not okay - 'nested' class is private!

what I want to know is, is there another way to define an inner class's method? and if not, is it eternally doomed to be inline because it has to be declared inside it's own class declaration?

View 5 Replies View Related

C++ :: Define A Class Arc Which Draws A Part Of Ellipse

Apr 24, 2014

The exercise is : Define a class Arc, which draws a part of an ellipse.

Hint: fl_arc()

And the body of the class ellipse is as follows in the book (PPP):

struct Ellipse :Shape {
Ellipse(Point p, int w, int h); //center, max and min distance from center
void draw_lines()const;
Point center()const;
Point focus1()const;
Point focus2()const;

[Code] ....

And the fl_arc() probably is part of FLTK which I've installed it on my machine.

Now the problem here is that while I don't can see the full version of the body of the ellipse how to do this exercise?

View 8 Replies View Related

C++ :: Define A Class For A Type Called CounterType

Apr 29, 2014

Define a class for a type called CounterType. An object of this type is used to count things, so it records a count that is a non-negative whole number.

Include a mutator function that sets the counter to a count given as an argument. Include member functions to increase the count by one and to decrease the count by one.

Be sure that no member function allows the value of the counter to become negative.

Also, include a member function that returns the current count value and one that outputs the count. Embed your class definition in a test program and run sufficient tests to verify it all works correctly.

View 3 Replies View Related

C++ :: Calling Custom Constructor Of Element In Array Whose Class Has Const Members?

Apr 15, 2013

If I have an array of some class, and that class has const members, is there some way I can call a custom constructor on elements of the array?

I can't seem to reinitialize an element in foos in the example below. A thread on stack overflow mentioned the copy constructor show allow it, but I get "no match for call to '(Foo) (Foo&)'" when I try it.

Code:
class Foo {
public:
Foo();

Foo(int x, int y);

[Code] .....

View 4 Replies View Related

C++ :: Nested Classes - How Members Be Accessed Through Object Of Enclosing Class Type

May 18, 2013

"A nested class has free access to all the static members of the enclosing class. All the instance members can be accessed through an object of the enclosing class type, or a pointer or reference to an object."

How can the members be accessed through an object of the enclosing class type? I understand the pointer and reference part because for them you dont need the full definition, but for creating a object you do?

Also it has free access to all static members because the nested class is part of the enclosed class and with static it exists in everything inside the enclosing class? Right or am I missing something?

View 4 Replies View Related

C/C++ :: How To Define Default Constructor For A Template List Class

Apr 18, 2012

I was making a template list class, and using it to make list of objects of my own class.It works fine with integers, but not with other classses.

template <typename T>
class CList {
public:
    struct Node {
        T data;
        Node* next;

[code]....

While in AddElement(), it gives error - Default constructor not available.

template<typename T>
bool CList<T>::AddElement(T t) {
    bool result = true;  
    if (head == NULL) {

[code]....

what is wrong here.

View 1 Replies View Related

C++ :: How To Define Static Member Data In Abstract Class

Jul 11, 2012

For example, in a header file A.h, I define an abstract class,

Code:

// A.h
class A {
public:
virtual void foo() = 0;
private:
static int _x;
};

How'd I initialize static member data _x?Normally, we initialize a static member data in a cpp file. However, there is not cpp file for A.h. If I intialize _x in header file, there will be linker errors like mulitple defined symbols. What is appropriate way to do that?

View 4 Replies View Related

C++ :: Do Static Functions Have Access To Non Static Data Members Of A Class

Apr 17, 2013

From my book:

"A static function might have this prototype:

static void Afunction(int n);

A static function can be called in relation to a particular object by a statement such as the following:

aBox.Afunction(10);

The function has no access to the non-static members of aBox. The same function could also be called without reference to an object. In this case, the statement would be:

CBox::Afunction(10);

where CBox is the class name. Using the class name and the scope resolution operator tells the compiler to which class Afunction() belongs."

Why exactly cant Afunction access non-static members?

View 7 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

C++ :: Define A Templated Class While Implementing Default Value On Templated Arguments?

Oct 23, 2013

I would like to define a templated class while implementing default value on templated arguments. I don't know how to do that with string templated variables.

For exemple:

Code:
template <class T>
class A {
public:
A() { version = ???? }
std::string_base<T> version;
};

I don't want to pass the default value as parameter of the constructor. how I can do this?

View 6 Replies View Related

C++ :: Template Class With Template Members

Feb 9, 2015

I have a class like this

PHP Code:
template<class X>
class A {
  X m_x;
public:
    X* foo();
    X* bar();
    //others are not related to X
}; 

I would like to get rid of

PHP Code: template<class X> 

For class level but still use it for members. Like this

PHP Code:
class A {
  X m_x;
public:
    template<class X>
    X* foo();
    template<class X>
    X* bar();
    //others are not related to X
}; 

However, I am still stuck at

PHP Code: X m_x; 

View 6 Replies View Related







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