C/C++ :: How To Remove Circular Dependency

Jan 23, 2014

I have ran into some sort of Circular dependency between two classes.

Forward declaration doesn't work as I'm allocating the memory for pointer array of Student and it requires the default constructor.

P.S I'm aware I haven't written the BIG 3, it's an incomplete code. Just want to know how to resolve this dependency.

class Student;
class Course {
char *name;
Student *s[3];

[Code].....

View 14 Replies


ADVERTISEMENT

C++ :: Circular Dependency In Template Arguments

Nov 7, 2013

Today I faced a problem where I had circular dependency in my template arguments. I was trying to make a class hierarchy similar to:

template<class BType>
class A_base {
public:
BType* getB();
};

[Code] .....

Basically I had objects that were of type A<B<A<B<...

Basically I have a tree like structure of heterogeneous types that must facilitate two-way interactions where A's can call B's and B's can call A's. This structure is useful in many contexts the difference is the methods A and B provide are different in each of these contexts. Instead of adding the getA and getB and all the other connectivity methods in every version of A and every version of B, I wanted to create a base class that managed this automatically.

Another piece of advice was break up your code so there is a forward-only and backwards-only dependent types. This is not a complete solution because the two cannot know about the other and this does not really facilitate arbitrary two-way communication (where A calls B then B calls A back). It also makes the code more complicated in that I have two sets of objects and interfaces.

So the solution was to make the template arguments specific to the things I wanted to be flexible. The connectivity interface of A_base and B_base should be constant. Hence that cannot be in the template parameter. It was merely the traits that I wanted to make flexible so... I came up with this solution:

#include <iostream>
template<class aTraitType,class bTraitType>
class A;
template<class aTraitType,class bTraitType>
class B;

[Code] ....

Now this compiles and works great. The problem is that aObj and bObj cannot call their opposite within a trait method because print() does not know anything about the connectivity. So the solution there was to make traits an abstract base class. Then magically everything works!

#include <iostream>
template<class aTraitType,class bTraitType>
class A_base;
template<class aTraitType,class bTraitType>
class B_base;

[Code] .....

So this outputs the following. Clearly there is two-way communication!

Class A is not connected to B
Class B is not connected to A
Class A at 0x7fff25d1aa10 reporting for duty
Class B at 0x7fff25d1aa00 reporting for duty
Class B at 0x7fff25d1aa00 reporting for duty
Class A at 0x7fff25d1aa10 reporting for duty
Class A at 0x7fff25d1aa10 reporting for duty
Class B at 0x7fff25d1aa00 reporting for duty

View 6 Replies View Related

C++ :: Doubly Linked List - Circular Dependency Error

May 15, 2013

When compiling the source I get the following error

"pms_program.h:54:56: error: expected declaration specifiers or ‘...’ before ‘CourseType’"

the code you are looking for in pms_course.h ( there is a circular dependency between pms.h , pms_course.h and pms_program.h)

function prototype AppendProgram ( part of doubly linked list )

I have attached the full course code.

As much as I like I cannot change the structure of the startup code ...

please see attached zip file for the entire source code.

View 6 Replies View Related

C++ :: What Is Dependency In Makefile

Aug 7, 2014

What is dependency in Makefile.

Secondly I have made Makefile but cannot use make -f . How to use it?

Third what is make [OPTION] [TARGET]

View 4 Replies View Related

C++ :: Class Definitions Have Interwoven Dependency

Mar 29, 2013

I have an exercise from my text that defines a StrBlob class, then a StrBlobPtr class to hold weak pointers to the StrBlobs. This is from C++ Primer (5th Edition) and coincidentally, the entire chapter is available on-line at here.

My problem is that the begin and end functions of StrBlob can't be defined until the entire StrBlobPtr class is defined. Forward declarations don't cut it, since begin and end need more than pointers.

The solution (if you also look at the errata for the book) seems to be to define StrBlob, leave begin and end undefined, then full define StrBlobPtr, and following that, finally define StrBlob::begin() and StrBlob::end().

Anyhow, the above works, as I show in the included code below - but it seems like a hack and messy. What would be the proper way to do this? My text may be obfuscating the issue in the pursuit of pedagogy.

Additionally, how would one separate StrBlob and StrBlobPtr into there own headers? I'd think it impossible, since the StrBlob would have to nestle an "#include "StrBlobPtr.hpp" in the center of it's own definition...?

Code:
#include <iostream>
#include <string>
#include <vector>
#include <memory>
#include <stdexcept>
class StrBlobPtr; // Forward declaration

[Code]....

As I said, the above works (compiles, haven't -tested- it extensively) but it seems messy.

View 2 Replies View Related

C# :: Breaking Dependency In Static Method For Unit Test?

Feb 6, 2014

I have function that returns historical data. I can access it, using file name. If I use file name, it reads that file and saves it to dictionary, so that in the future, if historical data is required for the same file, it does not read it again (it's lazy loading). If no file is supplied to the function, it tries to read file which is given in app settings.

However, for unit testing, I do not want to read any file. Instead, I want it to use small sample of hardcoded historical data. In order to do that, I think, I need to introduce interface to it. Then I can use some IoC to choose between different implementation for unit testing purpose and ordinary launch of application.

Function to get history is given as follows:

public static class Auxiliary
{
private static Dictionary<string, MyData> _myData;
public static MyData GetData(string fileName = null)
{
// ...
}
}

I have created default Unit Test project with Visual Studio so, as far as I know, by default it uses MSTest as test runner and MSUnit as unit testing framework but it does not have any IoC container so I should manage NuGet packages for solution and install Unity.

As far as I know, MSUnit (aka Moles) can unit test static methods (it's unconstrained isolation framework, like Typemock Isolator, unlike NUnit) but still many people suggest not to use any static methods for unit testing.

Should I use shim or stub [URL] Stubs should be used for faking external dependencies and here it is not external library, but my own code.

View 1 Replies View Related

C++ :: Application That Has One Static Library Dependency - Linking Error

Feb 16, 2012

I am trying to build an application that has one static library dependency, however I am getting this error when linking:

1>ClCompile:
1> All outputs are up-to-date.
1>LINK : fatal error LNK1104: cannot open file 'TestWrapperLib.obj'

Why I might be getting that? I have the .lib in the depends line, and the directory where it is at in the include line.

View 1 Replies View Related

C++ :: Circular Right Shift A Cstring

Jan 29, 2013

I need to circular right shift a cstring in C++

Let's say I have unsigned char test[10] = "HELLO!!!"; How would I go about circularly shifting this to the right? Inline assembly instructions would be ok too

View 6 Replies View Related

C++ :: Rotating A Circular Disk?

Aug 30, 2013

Any algorithm or function to rotate a displayed circle. To turn it 360 degrees like a car-tire. (It's needed to turn a turn-table in a model-railrod control program) .....

View 14 Replies View Related

C++ :: Circular Reference Not Working?

Mar 15, 2013

It's compiling but it's not working, it enters in stack overflow. It's a Doubly Linked List I'm compiling in Visual Studio. I think there's nothing wrong with this declaration, but there's just might be it:

class ListItem;
class List {
public:
ListItem *firstItemRef;

[Code] .....

View 7 Replies View Related

C/C++ :: Circular Permutation Through Function

Jan 17, 2015

I need to create such a function that the content of the first is put into the second, the content of the second into the third and the content of the third into the first.

For example, output should be like this
3
2
1
But the code below prints out:
1
2
2
Where am I making a mistake?

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

[Code]....

View 2 Replies View Related

C# :: Circular Progress Bar In WPF (Not Silverlight)

Jul 30, 2014

Is there a way to make a circular progress bar in WPF without using another library or NuGet Package?

Like a tutorial on how to make it from scratch?

Right now, I'm using the existing ProgressBar UserControl but it looks horrible especially after I change the Foreground color from Green to DarkBlue.

View 6 Replies View Related

C :: Circular Queue Based On Struct

Oct 6, 2013

I am stuck with how to make a circular queue that are based on a struct. Have been reading about the implementation but cant really understand it fully. Here is what i got so far.

Code:
#define SIZE 10
typedef struct {
char reg;
char brand;
int modelyear;
int mileage;

[Code] .....

View 8 Replies View Related

C++ :: Fixing Circular Dependencies With Pointers

Dec 18, 2012

I've been making a project that requires different files to have access to objects declared in other files such that circular dependencies are created. I've done some research and discovered that pointers and forward declarations should be able to fix this.

Example:

File 1 declares variable x, must edit x and y

File 2 must edit x and y, declares variable y

I know this isn't the best example, as you could probably declare x and y in the same file, but please suffice it to say that I'm unable to do that in my project.

View 10 Replies View Related

C++ :: Creating Circular Linked List

Jan 30, 2015

I've been making a circular linked list and I'm trying to assign each list a "name" and its next "link" but when I run my code it crashes.

Soldier *Head;
Head = NULL;
string names[] = {"Arman","Bogut","Castro","Damascus","Elene"};
for (int i = 0; i < 5; ++i) {

[Code] .....

View 4 Replies View Related

C/C++ :: Make Circular List And Print It

Apr 28, 2015

I have this program. I am trying to do this Circular List but i think something going wrong. The first of all is the list.The second is if my code for delete and select function are correct and the third i would like my program getting a "n" number of names and then make the circural list then print it and then when i select a number delete every node until give us the only one left.

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define SIZE 10
#define NUM_PER_LINE 6
typedef struct node {
char name[SIZE];
struct node * next;

[Code] .....

View 1 Replies View Related

C :: Access A FIFO (Circular Queue) Between Two Cores

Oct 31, 2014

I want to write a program where one core (core 0) will fill the FIFO and other core (core 1 ) will delete the data from FIFO.

Core 0:

I create a fifo

Code:
struct node
{
int info;
struct node *ptr;
}*front,*rear,*temp,*front1;

And my en-queue function is in core 0 and writing to specific memory location..(which works perfectly)

Code:
void enq(int data)
{
if (rear == NULL)
{
rear = (struct node *)malloc(1*sizeof(struct node));
rear->ptr = NULL;
rear->info = data;
front = rear;

[Code] ....

Now the problem is in the core 1. Here I am unable to read the values from the specific memory location. I am getting garbage value. Where I am doing some stupid error.. I did not understand

Code:
(front->ptr) = (unsigned int *) memory_location;

When I print the (front->ptr) it shows correct memory address but inside the De-queue function in core 1, I am getting wrong value..

Code:
int deq(int buf[n]) {
front1 = front;
printf("Val %d ", front->info); // showing wrong value
if (front1 == NULL) {
printf("

Error: Trying to display elements from empty queue");
return 0;

[Code] ...

View 8 Replies View Related

C++ :: Implementation Of Circular Queue Of Array Containing Names

Jun 28, 2013

/* Implementation of a circular queue of Array containg names.. */
# include <stdio.h>
# include <conio.h>
# include <stdlib.h>
# include <string.h>
# define QSIZE 5
typedef struct{

[Code] ....

I changed my code. but whenever i typed in the ILoveBacolod it takes it as a whole, and if i deleted it deletes the string not the letter. for example:

Enter String: ILoveBacolod
Enter a command: Delete (D)
Output: LoveBacolod
Enter a command: Delete (D)
Output: oveBacolod
Enter a command: Add (A)
Enter a character: z
Output: oveBacolodz

View 2 Replies View Related

C++ :: Circular Doubly Linked List Code

Feb 27, 2014

When I run this in main it gives me a windows error message. I believe it has something to do with my insertAtEnd function but I've gone over it a million times....

#include<iostream>
#include<string>
#include<vector>
#include"RhymeGame.h"
using namespace std;
Game::Game() {
head = NULL;

[Code] ....

View 3 Replies View Related

C++ :: Adding To The End Of A Doubly Linked Circular List?

Dec 2, 2014

Should my if statement be

if (tail== NULL) or if(tail->next == tail) ?

View 4 Replies View Related

C/C++ :: Reversing A Circular Doubly Linked List

Apr 25, 2015

I print the original list, then reverse it, then try to print it again. Here is what I get when I do that:

So that second line should print 2 1 4 5

Here is the reverse function:

void reverseCirListDeque(struct cirListDeque *q)
{
struct DLink *curr = q->Sentinel;
do{

[Code].....

View 2 Replies View Related

C/C++ :: Pointer To Last Node Of A Circular Linked List

Nov 30, 2014

Why is it sufficient to only have a pointer to the last node of the list?

View 3 Replies View Related

Visual C++ :: No Circular References But Undeclared Identifier

Jun 11, 2014

Each of my header includes is protected by directives. I think I don't have to include Boolean in my work space because it is already included in the external dependencies section. and the Boolean.h is in the include path.

MachineShop, Boolean etc got undeclared identifier error

Tried to comment out the directives, to no avail.

Code:
#include <iostream>
#include <string.h>
#ifndef BOOLEAN_H_
# include "Boolean.h"
#endif
#ifndef PROCESS_H_
# include "Process.h"
#endif
#ifndef MACHINESHOP_H_

[Code] ....

View 2 Replies View Related

C/C++ :: Add Function To Tail Of A Doubly Linked Circular List

Nov 30, 2014

I have a function that I would like to add to tail. It is not correct.

template<class T>
void DoublyLinkedCircularList<T> :: addToTail(T element) {
DoublyLinkedNode<T>* head;
DoublyLinkedNode<T>* temp;
temp->element = element;

[Code] .....

How do I fix it?

View 14 Replies View Related

C/C++ :: Circular Buffer In The Form Of Finite State Machine

Dec 11, 2014

I'm supposed to create a circular buffer that reads an input file and outputs data after running though basically an integral equation. Everything my be referenced by pointers. When I build I am being told segmentation fault: 11. From what I have gathered that means there is a problem with my memory allocation correct? I'm including the custom header file and the main.c as well.

header file :

#ifndef FSM_H
#defineFSM_H
#define INPUT_BUFFER_LENGTH 2
#define OUTPUT_BUFFER_LENGTH 2
#define INITIAL_INPUT {0,0}
#define INITIAL_OUTPUT {0,0}

[Code] .....

View 1 Replies View Related

C :: Circular Queue Using DLL With Globally Declared Pointers Not Being Properly Initialize

Jan 29, 2014

I have a circular queue using DLL which is using globally declared pointers. The problem now is that it is not being initialize properly or being cleared thus my code is not working as expected.

In my code you will be asked how many nodes do you wish to enter "i made 2 default for now", after that you may then add or delete the node. add only works now since delete is still on progress.

When you add the nodes "2 nodes by default" the program will only record the latest input so if i were to input 1 and 2, only 2 will be displayed. I know that this maybe because of my *first and *last variables not being initialize properly.

How should i really work with global pointers? Also im really new to project file programming and not a fan of pointers or linked list at all.

main.c
Code:
void main(){
int ch, number, numdum = 0;
n *new, *ptr, *prev, *first, *last;
first = NULL;
last = NULL;
clrscr();
printf("Enter number of nodes: ");
scanf("%d", &number);

[Code] .....

View 5 Replies View Related







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