C++ :: Struct At Inside Of Class?

Jun 23, 2013

while writing code i got a question. For example i created a class named as unit.

Think a simple game, and the unit class will belong the units.İf i give the preferences as private one by one, it will be irregular. For a detailed game; height, weight, race, hair preferences, eyes... Strength, dexterity, charisma, intelligence, wisdom, constution... experience, damage, armor...

and should i use struct to group them? And how to can i use struct at the inside of class as private?

View 2 Replies


ADVERTISEMENT

C++ :: Typedef And Struct Inside Class Definition?

Jul 22, 2013

Can typedef and struct be put inside a class like below?

Code:
class classA {
private:
typedef void(classA::*aFnPtr_t) (); //pointer-to-member function
struct strctA {
int a;
int b[100];
};
typedef struct strctA strctA_t;
typedef void (classA::*bFnPtr_t)(strctA_t*); //pointer-to-member function
...
}

View 8 Replies View Related

C++ :: Accessing Inside Structure Via Struct Pointer To Struct Pointer

Jun 5, 2012

"
#include <stdio.h>
struct datastructure {
char character;
};
void function(struct datastructure** ptr);

[Code] ....

These codes give these errors:

error: request for member 'character' in '* ptr', which is of non-class type 'datastructure*'
error: request for member 'character' in '* ptr', which is of non-class type 'datastructure*'

These errors are related to
"
*ptr->character='a';
printf("Ptr: %c",*ptr->character);
"

I want to access "character" data inside the structure "trial" by a pointer to pointer "ptr" inside function "function",but I couldn't find a way to do this.

View 3 Replies View Related

C++ :: Struct Inheriting From A Class Or A Class Inherit From A Struct?

Mar 9, 2012

I just read and have known for a while that classes are private (members and inheritance) by default and structs are public. But my question then comes what if.. a struct inheriting from a class or a class inheriting from a struct?

View 3 Replies View Related

C :: Set Struct Member Variable For Structure Inside Def

Mar 12, 2014

This is with Linux gcc

Code:
typedef struct _a
{
int id;
} a;
typedef struct _b
{
a my_a;
my_a.id = 1; // error: expected specifier-qualifier-list before "my_a"
} b;

I get error: expected specifier-qualifier-list before "my_a"

I must set the id for the kind of struct created inside the struct def because main() will be casting based on this id. Thats how I will know which structure b contains by it's id, there could be hundards of different structs with different values I will cast to the correct one and know it's members by it's id. How do I ?

View 10 Replies View Related

C :: Function Pointer Inside A Typedef Struct

Aug 25, 2014

I want to have a function pointer inside a typedef struct but I get a segmentation fault when I run my code. Here's my code:

#include <stdio.h>
typedef struct Foo {
void (*bar)(int);
} Foo;

void func(int x) {
printf("display: %d

[Code] ....

View 2 Replies View Related

C/C++ :: Displaying Array Elements Inside Struct

Feb 13, 2015

How can I display the elements of an array inside struct something like this

struct ABC {
double a[3];}
void show( const ABC & x );
ABC x{18, 'W', { 1.1, 2.2, 3.3 }};
show(x); would output {18, ‘W’, {1.1, 2.2, 3.3}}

View 10 Replies View Related

C :: Appcrash Segmentation Fault Char Inside Struct

Apr 24, 2013

Code:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

typedef struct info info;

[Code] ....

View 2 Replies View Related

C++ :: Make Class Created Static Inside Another Class?

Dec 17, 2013

it seems everytime i use statics in a class i come across with a porblem.

this time i wanted to make a class i created static inside another class.

MainVariables.h file
static fge::window mWinMain;

if someone ever wants to reach it
MainVariables.cpp file

fge::window MainVariables::mWinMain;
...
...
fge::window MainVariables::GetWinMain()
{
return mWinMain;
}

but when i created some other MainVariables classes at other places instead of them reaching to the same window two window is being created.

yes i know maybe there are better methods but currently i m working on polymorphism and i need some static members.

View 2 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++ :: Call From Class Created Inside A Class

May 21, 2014

I have 2 Classes.
-> StateManager
-> Intro

The StateManager creates the Intro. I want that the Intro calls a function of the StateManager if finished. How can I achieve that?

At line 24 at the Intro class you can see what I tried.

StateManager:

#pragma once

#include "State.h"
#include "Intro.h"
class StateManager{
private:
std::vector <State*> States;

[Code] .....

View 5 Replies View Related

C++ :: How To Create A Class Object Inside Another Class

Feb 20, 2015

My thought is that I would need to establish a variable for the class in the header and call the class within the .cpp file

//class A.h
B b;

Then in class A, to create the object and use a method from the object I would -

//class A.cpp
A::A(){
b();
}
int someAmethod(){
b.bmethod();
}

View 6 Replies View Related

C++ :: Initializing Object Of Class Inside Another Class?

Mar 7, 2014

I have a class MySeqBuildBlockModule that I am inheriting from: public SeqBuildBlock. Other than constructor and destructor, this class MySeqBuildBlockModule has a method: prep.

class MySeqBuildBlockModule: public SeqBuildBlock {
friend class SeqBuildBlockIRns;
public:
MySeqBuildBlockModule (SBBList* pSBBList0, long TI1_In, long TI2_In)// more arguements in this constructor of derived class
: SeqBuildBlock (pSBBList0)

[code]....

I would have like to intiantiate an object "myIRns_3" of a class defined in third party library

SeqBuildBlockIRns myIRns_3(pSBBList2);

and would like to access it from the prep function as:

double dEnergyAllSBBs_DK = myIRns_3.getEnergyPerRequest();

I tried to instantiate following in either private section or in constructor; but w/o any success:

SeqBuildBlockIRns myIRns_3(pSBBList2);

ERRORS encountered:

When I tried to do it inside the constructor, I get the following errors:

MySBBModule.h(113) : error C2065: 'myIRns_3' : undeclared identifier
MySBBModule.h(113) : error C2228: left of '.getEnergyPerRequest' must have class/struct/union type
MySBBModule.h(116) : error C2065: 'pSBBList' : undeclared identifier
MySBBModule.h(116) : error C2227: left of '->prepSBBAll' must point to class/struct/union

When I tried to do it in private section, I get the following errors:

MySBBModule.h(106) : error C2061: syntax error : identifier 'pSBBList2'
MySBBModule.h(113) : error C2228: left of '.getEnergyPerRequest' must have class/struct/union type
MySBBModule.h(116) : error C2065: 'pSBBList' : undeclared identifier
MySBBModule.h(116) : error C2227: left of '->prepSBBAll' must point to class/struct/union

View 5 Replies View Related

C++ :: Declaring Array Inside A Class

Apr 18, 2013

class Hallway {
private:
//---------------------------------------------------------------
// DO_04: Declare a Light array of size MAX_LIGHTS
// Hint: look through the methods below to find the name to use
// for the array
//---------------------------------------------------------------

int numLights;
int lights[MAX_LIGHTS];

[Code] .....

I keep getting the error " this.lights[i] is not a struct or class and so you cannot use '.' " on line 34.

How am I supposed to define my lights[] array? I can't modify anything except directly after each comment block.

View 6 Replies View Related

C++ :: Object Inside Class Becomes NULL?

Nov 18, 2013

I have built LOG4CXX lib and DLL and trying to use it in my application

Loh.h
class Log
{
public:

[Code].....

In my main I am initializing Log class object and calling Debug method to log debug message to a file.

Issue I am facing is at if(CLogger::oLogger != NULL) which is always returning oLogger as NULL.

View 1 Replies View Related

C/C++ :: Calling Functions Inside A Class?

Nov 4, 2014

Im currently working on a class assignment and the pseudo code containing the instructions that I need to complete list:

//--------------------------------------------------------------------------------------------------------------
// CTOR: Point()
//
// DESCRIPTION
// Default constructor. Initializes the point to be at the origin (0, 0) and the color to black = (0, 0, 0).
//
// PSEUDOCODE
// Call Init() and pass 0, 0, 0, 0, and 0 as the parameters.
//--------------------------------------------------------------------------------------------------------------

My code for this is:

Point::Point(){
void Init(0, 0, 0, 0, 0);
}

The code I wrote for the function Init is here:

Point::Init(int mX, int mY, color mColor){
mX = 0;
mY = 0;
mColor = pInitColor;
}

My problem here is that whenever I try calling this function in the point class, I get an error next to void Init saying incomplete type is not allowed. Also visual studio is telling me that it expects a ')' after my first zero in that line.

View 1 Replies View Related

C/C++ :: Offset Function Inside Class?

Jan 1, 2013

i usually use this method for accesing functions in executables, the code is executed from a DLL (always works, except when the function are inside of a class, even tho is public):

.h:

typedef int (*pgObjViewportClose) (OBJECTSTRUCT* gObj);
extern pgObjViewportClose gObjViewportClose;

.cpp

pgObjViewportClose gObjViewportClose = (pgObjViewportClose) 0x04F1940;

That works, but i can't get it to work if the accesing function is inside of a class, i get Unhandled Exception while trying to access a function inside a class, is there a way to do it?.

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++ :: Class Definition Inside Function Body

Mar 3, 2013

Is this standard-compliant code?

int f() {
class C {
public:
int mf() const {return 1;}
};
C c;
return c.mf();
}

View 1 Replies View Related

C++ :: How To Return Element In Array That Is Inside A Class

Nov 16, 2014

I have a program where I roll a die X number of times and need to print how many times it lands on each side. I tried to create an array in the class aDie that increments each time the corresponding number is rolled but when I go to call and print it in the main my out put is 0. I just picked how many times it landed on the side 4 just to see if it works and it doesn't.

#define ADIE_H
#include <iostream>
#include <vector>
#include <cstdlib>
#include <ctime>
using namespace std;
class aDie {

[Code] .....

View 3 Replies View Related

C++ :: Proper Way Of Using String Array Inside A Class

Jul 23, 2014

class myclass{
string myarray[5];
myarray[0] = "one"; myarray[1] = "two"; myarray[2] = "three"; myarray[3] = "four";
myarray[4] = "five";
};

this works in main function but doesn't work in the class;

1. Why this methods doesn't work inside class but works in main function?
2. What is the proper way of using string array inside a class?

View 4 Replies View Related

C++ :: Coding A Loop Inside A Class To Use In Main

Feb 22, 2013

I am writing a program where all work is done in the class methods. Main is used to call the methods. I need to know how to get a loop to work without any variables in main that can be used outside the methods. This is what I have in main:

#include <iostream>
#include <string>
using namespace std;
#include "FerryBoat.h"
int main() {
//create a constructor for a ferry boat
FerryBoat myBoat('B', 20, 'A');

[Code] ....

View 3 Replies View Related

C/C++ :: Overload Two Different Operators One Inside Class And Other Outside Using Friend

Nov 23, 2014

I'm trying to understand the basics of oop ...

#include <iostream>
using namespace std;
template <typename T>
class max_vector {
private:
T* elemente;
int lungime;

[Code] ....

The purpose of this program is to overload two different operators one inside the class, and the other one outside using friend. The problem is that i get 1 error at the '*' one.

View 1 Replies View Related

C++ :: Add Variable Address To Void Pointer Inside Of Class?

Dec 1, 2013

How can I add the variable adress to a void pointer inside of a class?

class variant2 {
private:
void *Vvariant=NULL;
public:
template<typename b>
variant & operator = (b *adress)

[Code] ....

if possible i want avoid the '&' when i assign the variable address.(variant2 f=varname;//like you see i don't use the '&')
for the moment i just need put the address to Variant pointer. but i receive several errors .

View 4 Replies View Related

C++ :: How To Declare Array With Constant Size Inside Of Class

Jul 29, 2013

I wanted to add that the template argument is needed because its a "special case" but if that doesn't work what would be the next best way to solve this problem. I want to be able to declare the const size of the array outside the class far removed from it actually. I'm actually going off this page

[URL] .....

Heres the code

#include <iostream>
template <int F>
class C
{

[Code]....

View 2 Replies View Related

C++ :: Variable Inside A Class - How To Manage Memory Allocation

Jul 30, 2014

recently I developed a class header only in C++ to deal with byte arrays. Since I developed programs in other languages that had some libraries to dial with byte arrays, I developed one that the syntax is very similar to other languages.

Since I'm not very familiar with memory management, I was concerned about somethings I've read about (ex: memory fragmentation).

Here is a very simple example of my practice:

class ByteArray {
public:
ByteArray(size_t size) {
buffer = (int8_t*)malloc(size);
}

[Code].....

The class is intended to be used as part of comunication protocol in a webserver, byte arrays are created and destroyed a lot. Should I use pools? Is there a better practice? Am I doing everything wrong (laugh)?

For those who wants to see the entire class: [URL]

View 9 Replies View Related







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