C/C++ :: Nested Classes Aren't Reading Others As Types

Apr 4, 2015

I have a program to make a contact book. Included below i will post both header files and cpp files of my contact book, my contact class, and my address class. and my main.cpp. The reason address and contact are separate was because my teacher had us do an exercise where we used a header file of someone else's code, and didn't know what the functions actually implemented. But as the project has progressed he gave us the cpp for address.

Main.cpp
#include "Address.h"
#include "ContactBook.h"
#include "Contact.h"

[Code].....

View 9 Replies


ADVERTISEMENT

C++ :: Nested Classes And Structs

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

C++ :: Assign A Class Value To Another Nested Classes?

Jul 17, 2013

this is the first time to ask my question on Cplusplus. my qustion is i got this message when i trying to run this code:

object.h
#ifndef __NCTUNS_nslobject_h__
#define __NCTUNS_nslobject_h__
#include <stdio.h>

[Code].....

so, my problem is when the compiler starts compiling it stops on this code :

NslObject::newKeyPair (RSA::GenerateKeyPair(keyLength));

and the appeared message is :

Error:
object.cc: In function ‘void Set_KeyPair()’:
object.cc:53: error: no match for call to ‘(KeyPair) (KeyPair&)’

so, how could i assign a generated keypair class value to NslObject::newKeyPair.

View 2 Replies View Related

C++ :: Linked List With Nested Classes

Apr 30, 2013

how I would execute a nested class in a linked list... As example;

[Character][Weapon][Spell] classes are children of a [Base] class that stores normalized information such as 'Name'...

I am aiming to have a unique Character with a unique Weapon and Spell. I am trying to link-list these to have multiple characters. I just can't apply the design logic into programming logic.

cNode.h
#pragma once
#include "Includes.h"
class cNode

[Code]....

View 1 Replies View Related

C++ :: Way To Restrict A Template-capture To Certain Types / Classes

Nov 16, 2014

I was creating a template and I realized that certain data-types/structs/classes would not be applicable to my template.This would cause bugs and errors if used incorrectly. Is there a way to restrict a template-capture to certain types/classes?

View 2 Replies View Related

C++ :: Accessing Classes Member Variables Nested Inside Another Class

Feb 22, 2013

I have two classes, a Package class and a Person class. The Package class has two Person objects has member variables, a Sender and a Receiver. While overloading the << operator for the Package class so that it will make an output label from everything in the Package class. Here is my code...

class Package{
public:
Person Sender;
Person Reciever;
int weight;
double cost;
friend ostream &operator<<(ostream &out, Package &pack);

[Code] .....

So my problem is on that last output line, I am unable to call Sender.getName()... etc. Is there a proper syntax so that I can access the members of the Person class while overloading the << operator for the Package class?

View 2 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++ :: Reading Different Types Of Input Into Array

Jun 30, 2012

Let's say I have a list of words that are followed by a number.

Word 1
Word 2
Word 3
Word 4

I need two arrays. One for the words and one for the numbers.

Code:
string STORE_ARRAY[100];// stores string (word)
string operation[STORE_ARRAY];
int PARA_ARRAY[50];//stores parameter (#)
int parameter[PARA_ARRRAY];

For the file input, I'm using this:

Code:
in.is_open()){
string line;
while(getstring filename;
cin>>filename;
vector<string> file_input;

[Code] ....

So first it gets saved in file_input, but then it needs to split it and move it into the appropriate array.

View 2 Replies View Related

C++ :: Reading Mixed Data Types From A File

Mar 28, 2015

How to properly read data from a .txt file.

If I have data stored in a .txt file, which is formatted/stored like this:

Code:
Apples and Strawberrys
10
Cherrys
12
Pears
16
Grapes, Melons, and Peaches
20

I know that if I read/extract, and print the data like this;

Code:
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
int main() {
ifstream dataFile("test.txt");
string textData;
[Code] ....

Each line of data is stored in the string "textData" and printed to the screen, exactly as it was stored in the .txt file. So, all is clear to me up to that point.

But, what if I wanted to store each line of text in the string "textData", and store the numbers/integers into a separate variable called "numberData"? How would I retrieve and store the numbers (in the above example .txt file, every 2nd line) separately from the text?

For now, to keep things simple, let's assume that the data in the .txt file is stored/formatted as in my example (1 line of text, 1 line containing a number/integer, ...repeat) so, there is no need to test if the retrieved data is actually text or an integer, before it is stored in the appropriate variable type.

View 14 Replies View Related

C :: Consumer And Producer Threads Aren't Synchronizing Correctly?

Dec 3, 2013

I have a school assignment to create a program that uses a producer thread to create a series of random numbers, and a consumer thread to read those numbers (via a shared bounded buffer), and record the min, max, average, and number of items. Now, the threads aren't synching well. Here's my code:

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

pthread_cond_t empty;
pthread_cond_t full;
int done = 0;
pthread_mutex_t lock;

[code] ....

And output:

Code:
Producer in for
Consumer Entering While
Consumer reading item 0
Producer making item 0
Consumer reading item 1
Consumer reading item 2
Consumer reading item 3
Producer making item 1
Producer making item 2
Producer making item 3
Producer making item 4
Producer making item 5
Producer making item 6
Consumer reading item 4
Minimum: 0
Maximum: 4978
Average: 995
Items Produced: 5

View 4 Replies View Related

C :: Parameter Names Without Types And Conflicting Types In Fgets

Jan 22, 2014

I have this

Code:

#include<stdio.h>
#include<ctype.h>
#include<string.h>

int check_up(char string[]);
int check_low(char string[]);
void to_up(char string[]);
void to_low(char string[]);

[Code] .....

When I compile this I have the following problems: warning: data definition has no type or storage class [enabled by default] in 'to_up(word)'conflicting types in 'to_up' function and to_low function warning: data definition has no type or storage class [enabled by default] into_up function error: unknown type name "word" in line 'printf("All uppercase %s. ", word):;'warning: parameter names (without types) in function declaration [enabled by default] in 'to_up(word)'and 'to_low(word)' 'note: previous declaration of "to_up" was here in function declaration of to_up function

View 7 Replies View Related

C++ :: Place Nested Loop Where Nested Not Necessary?

Apr 3, 2014

I wrote this code, and everything was working well, but part of the assignment is that it must include nested loops. Once I added the nested while loop, which is basically an if statement, my life was ruined. I am trying to nest a loop in the code that will basically tell the compiler that if the value "loopVol" were to exceed the value of "final" after adding an increment, to run the program for the "final". How can I do that?

Example:

initial = 10
final = 123
increment = 10

as of now, the program would stop at 120, but I want to nest a loop that will tell the compiler to calculate at the final if this happens.

#include <iostream>
#include <iomanip>
#include <stdio.h>

[Code]......

View 3 Replies View Related

C++ :: Array Of Classes With Classes Inside

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

C :: Nested For Loops

Jun 1, 2013

What output would you expect from this program?" The output was not what I expected. I've psuedo-coded this out and I'm still missing something.

Code:

#include <stdio.h>
int main () {
int numbers[10] = { 1, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
int i, j;
}

[code]....

The output: Code: 1 1 2 4 8 16 32 64 128 256 So when I look at this first loop I see that j = 0, which is less than 10, so then the program statement should commence, which is another for loop. So in this inner for loop I see that i = 0, which is not less than j, so this loop should terminate. Then the value of j increments by 1 and the first go around of the loop has completed.

Now I see that j = 1, so this is less than 10, and the inner for loop commences once again. This time though, i actually is less than j, so numbers[1] = numbers[1] + numbers [0], or numbers[1] = 0 + 1. Now the value of i is incremented by 1 and the first go around of this inner loop has completed. Then the value of j increments by 1 and another go around of that loop has completed.

So now j = 2, i = 1, and numbers[2] ( which is 0 ) = numbers[2] + numbers[1], or numbers[2] = 0 + 1. I was expecting the output to be an array full of 1's. However this is not the case..

View 6 Replies View Related

C/C++ :: How To Clear Nested Stl Map

May 21, 2013

here is a nested stl map

typedef struct struct_RISCP {    
        float nSCPTotal;
        int nSCPCount;
        CString strIMEI;  
        std::map<UINT8, int> mapSection;    
    }RISCPSt;
map<stRncCellIdntyDmnType, RISCPSt>m_mapRISCP;

it occupied too much memory,i wanted to clear them(both outer map and inner map) ,some one told me you just need to call m_mapRISCP.clear(),then the mapSection (inner map) will be cleared automaticly,in other words, m_mapRISCP.clear() will clear both outer map and inner map.

View 5 Replies View Related

C++ :: Nested Conditional Operations

Feb 4, 2014

So I think I am having syntactical problem with my code.

Code:
int main() {
vector<int> ivec;
int score;
[Code] ....

I get an error from my compiler on the ?10th? line (Nested condition line) that says |19|error: invalid operands of types 'int' and '<unresolved overloaded function type>' to binary 'operator<<'|

The purpose of the program is to take input and store it in a vector and then change the value to be between 1-6. I made this for the purpose of learning about nested conditional operations.

View 3 Replies View Related

C :: How To Make Nested Loops

Dec 7, 2013

Howi can made nested loops?

Code:

for (yax=0; yax<10; yax=yax+1) {
for (xax=0; xax<100; xax=xax+1) {
printf("%d
",yax);
}
}

way what i tired dont work. or maybe works but why this prints only zeros ?

View 8 Replies View Related

C++ :: Variable Nested For Loop

Mar 25, 2013

This code is used in scientific calculation for optimization problem.

Basically a particle is moving in a three dimensional space, its position is (x,y,z).

At each position, there is a fitness value associated with that position.

The fitness value is given by fitness(x,y,z) (code line 12~19).

We need to find out, when the particle moves around randomly, what is the highest possible fitness value.

To solve this, below code is used, and it produces correct result.

#define DIMENSION 3
#define MAXX 4
#define MINX 0
#define MESHsize 1
#include <iostream>
using namespace std;
float maxValue = 0.0;

[Code] ....

The output of the code:

[ fitness(0,0,0) = 0] [ fitness(0,0,1) = 1] [ fitness(0,0,2) = 4] [ fitness(0,0,3) = 9]
[ fitness(0,1,0) = 1] [ fitness(0,1,1) = 2] [ fitness(0,1,2) = 5] [ fitness(0,1,3) = 10]
[ fitness(0,2,0) = 4] [ fitness(0,2,1) = 5] [ fitness(0,2,2) = 8] [ fitness(0,2,3) = 13]
[ fitness(0,3,0) = 9] [ fitness(0,3,1) = 10] [ fitness(0,3,2) = 13] [ fitness(0,3,3) = 18]

..... so on

Answer: highest fitness = 27

Note: In this case, the values of x,y and z is integers from 0 to 3 inclusive.

For 3-dimensional space above, actually the code had run through 3 nested "for" loops.

Question: Above code works for 3-dimensional space. How to generalize the code, so that it works also for N-dimensional space, where N is an arbitrary integer?

( Note: possibly N = 30 )

View 19 Replies View Related

C++ :: Vector In Nested Structure

Nov 26, 2013

I have a nested record structure in C++ that contains a FileHeader record, a RecordHeader record and a DataRecord record. The last item is an array of unknown size (at compile time). I have to open a file and read the array size and then create the array.

I have worked on this for some time and can't figure out how to make it work. I know the sample data I am using has 85 records. I insert 85 into the array size and it works fine. But how do I create a dynamic array or define a vector within a nested structure?

1. What is the best (easiest) method to accomplish this (array or vector)?
2. How would it be implemented/how do you add data to it?

PreviousLogRecord.FaultRecord.push_back(field1); // does not work
PreviousLogRecord.FaultRecord[recordNumber].field1 = somedata; // works with 85 in array size.
struct LogFileHeaderRecordType {
QString field1;
int field2;

[Code] .....

View 3 Replies View Related

C/C++ :: Triangles With Nested For Loops?

Sep 27, 2014

So in class our teacher assigned us a program where we have to use nested for loops to creates triangles. How does the 2nd for loop print more than 1 star? since the for loop will only run the cout 1 time until it gets to the escape sequence, how does it print more than 1 star on a line? this is what is confusing me. I feel like if i can grasp the understanding of that and what the for loops are doing i can finish the rest of this program with ease

#include<iostream>
using namespace std;
int main()

[Code].....

View 1 Replies View Related

C/C++ :: Nested For Loop Pattern?

Nov 3, 2014

I'm trying to output a pattern using loops. The pattern is a plus symbol made of 3 rows of 5 x's followed by 3 rows of 15 x's and finally 3 rows of 5 x's.

I can get the program to output all 9 rows with 5 x's but I don't know how to do the 3 rows of 15 in the middle. I have tried a while loop and also an if statement but nothing seems to work.

#include "stdafx.h"
#include <iostream>
#include <iomanip>

[Code]....

View 8 Replies View Related

C++ :: Finding Nested Header Files?

Aug 27, 2013

I'm working with CGAL - Computational Geometry Algorithms Library, which is a library of geometry functions declared as several thousand header-only files. When I run a basic program (source code [URL] ) I get this output: [URL]

I have tried switching angle brackets to quotes. I have also started reading up on CMake.

Do I need to walk the dependency tree and add all of those files to my CMakeLists.txt? Or is there a way to tell the compiler to look in subdirectories?

View 2 Replies View Related

C++ :: Nested / Recursive Template Specialization

Feb 11, 2014

I'm trying to write some naive binary serialization code and wanted to cut down on repetition of logic for serializing/deserializing nested vectors or other STL containers to reduce the chance of typos etc, and thought templates might hold a solution for me.

Code:
template <typename T> void serializeField(IWriter& writer, const T& val) {
writer.write((char*)&val, sizeof(T));
}

template<typename U, typename V>
template <> void serializeField(IWriter& writer, const U<V>& collection)

[Code] ....

Is there a way to do something like this? It isn't a big deal for me to just manually write code to serialize my vectors to the needed depth, but it sure would be nice to get this working.

View 10 Replies View Related

C :: How To Access Nested Structure Using Pointer

Jan 22, 2015

I need to know how to access the nested structure using pointer, i mean i know how to do that when i have simple structure, for example:

Code:
struct person{
char fname[16], lname[16];
int age;
}

for this example i can use

Code: (*pointer).age
or
Code: pointer->age

But if i have structure like this:

Code:
struct date{
int day, month, year;
}
struct person{
char fname[16], lname[16];
struct date birthDate;
}

Then how can i access the birthDate using pointer?

View 2 Replies View Related

C :: Breaking Out Of While Loop With Nested If Statements

Mar 14, 2014

Code:

while(x==1){
for (i=0;i<j;i++)
{if (word1[i] == word2[i])
{prefix[i]= word2[i];
counter++;}
else
x=2;}

Basically after the 3rd run of the for loop, it encounters a contradiction. I want it to exit right there and then. Instead it continues to run the for loop. What can I do?

View 4 Replies View Related

C :: Nested Loops - Asterisk Diamond

Jul 11, 2013

Getting close but I think I am stuck on the second loop. The input you put in will be doubled (and it's not supposed to).

Code:
int main() {
int n, i, j, k;
printf("What would you like the height to be? (Positive odd integer)
");
scanf("%d", &n);

[Code] .....

View 3 Replies View Related







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