C++ :: Friend Functions And Classes Not Permitted To Data

Dec 29, 2013

I have a situation: I have a class character

class Character;
class Village;
class Character {
public:
//Functions
void charGen(); //Character creation

[Code] .....

According to the Friendship and Inheritance tutorial [URL] ...., that code should work, but it doesn't. I am given an error: undefined reference to questsCompleted

The compiler I am using is Code::Blocks ....

View 4 Replies


ADVERTISEMENT

C++ :: Can A Friend Function Work For Two Classes?

Mar 23, 2013

If yes then how?

View 6 Replies View Related

Visual C++ :: Friend Classes In Separate Header Files?

Nov 25, 2012

I am struggling to enable friendship between two classes in separate header files for a banking program.

I am attempting to get the Person class to use variables from the Account class. Heres what I have so far.

ACCOUNT.h:

Code:
#include<iostream>
#include<fstream>
#include<cctype>
#include<iomanip>
#include <string>
#include <math.h>
#include <windows.h>
#include <vector>
#include "Person.h"
using namespace std;
class person;

[code].....

View 3 Replies View Related

C++ :: Namespaces And Friend Functions

Sep 3, 2014

Are there any special considerations when using friend functions and namespaces?

objid.h

#pragma once
namespace FOO
{ typedef ULONGobjid_t;

class OBJID
{FOO::objid_tm_objnum;

[Code] ....

My C++03 compiler is giving me the following error:

C:devDATALIBOBJID.cpp(42,14) : error (346) : member "FOO::OBJID::m_objnum" is inaccessible

Is this a compiler issue, or am I missing something here trying to use a friend function? If I don't put the OBJID class in a namespace, everything compiles fine.

View 2 Replies View Related

C++ :: Friend Functions - Variable Out Of Scope

Oct 11, 2014

I'm trying out friend functions not in just one source file to see how it works but I'm getting an error.

/* ----- ClassOne.h ----- */
#ifndef CLASSONE_H_
#define CLASSONE_H_
#include "classTwo.h"
using namespace std;
class ClassOne {

[Code] ....

Basically, I just want to print out the private members of ClassOne using ClassTwo's friend function twoPrintsOne().

The error is in classTwo.cpp and it says that m_a and m_b in the twoPrintsOne function are not declared in this scope.

View 3 Replies View Related

C++ :: Operator Overloading And Friend Functions

May 3, 2013

Can an overloaded operator be a friend function?

View 7 Replies View Related

C++ :: Including Outside Functions Into Classes?

Mar 6, 2015

I have a hpp file with a list of inline finctions like this:

Code:
inline int check() {
return 1;
}
inline int check_1() {
return 1;
}

... What I would like to do is to include them into several unrelated classes. How can I do this. Can I just add the hpp inline functions in headers of my class containing files or not. I mean if they are not defined as class functions how can they be called. I don't understan the logic.

View 2 Replies View Related

C++ :: Using Virtual Functions In Base Classes

Oct 19, 2014

I recall when I first started playing with C++ I was told that you should never use virtual functions unless you absolutely cannot think of a better way to do whatever you are attempting. This is something I have tried to stick to over the years - and indeed is probably why I have never used inheritance or polymorphism much in my own programmes.

However, I notice through a great deal of the code examples offered to questions here and even over on StackOverflow that commentators show no hesitation to recommend code that involves virtual functions. More so, I have even seen several instances here where - what I was taught as, but they may well have a different official name - 'pure virtual functions' (those with definitions inside a class of something like virtual int function_name(void)=0) are demonstrated and I was very clearly taught to avoid those like the plague.

I was wondering therefore has the official thinking changed since the middle nineties on when - and even whether - to use virtual functions in your programmes?

View 9 Replies View Related

C++ :: Pure Virtual Functions - Abstract Classes

Jan 26, 2013

when I should use pure virtual functions.On the one hand, "TOY" for example should be an abstract class since theres no such thing as "TOY" , there are "toy cars", "toy fighters" etc , but on the other hand I need to force it somehow to be abstract since theres no really a function that any toy should have and implement on his own way (except PRINT maybe).

when I should REALLY use pure virtual functions? And if I want to avoid people from creating TOY objects (for example), the only way is PURE virtual functions. right?

View 4 Replies View Related

C++ :: Virtual Functions From 2 Separate Base Classes?

Sep 11, 2014

So I have 2 seperate base classes, (note that I removed the variables and functions that do not relate to the topic) Object.h

class Object{
public:
Object();
~Object();

[Code].....

The error I get is saying I am calling a function declared with one calling convention with a function pointer declared with a different calling convention and this makes perfect sense because for some reason, the function pointer is pointed at the virtual function Object::update but I can't figure out why and how to make it point at the virtual function Drawable::getImage.

Also, the virtual update function is called in a different place just before this and works correctly.

View 6 Replies View Related

C/C++ :: Access Derived Classes Functions On A Vector

Jan 19, 2014

I need to access the functions of the derived classes from a vector of objects of base classes (can't believe I wrote it). Here a Diagram for you to understand:

So as you see, I need the function Use() from the Usable class, to be able to be called from the vector like:

inventory.at(x)->Use()

View 14 Replies View Related

C++ :: Linked List - Friendship Of Functions Related To Classes

Jul 5, 2013

I'm developing a stack using a linked list. I have to develop two friend functions to do something with the list. But I've tried to understand the friendship, without any consistent result.

Extract of code:

Code:
class Element {
public:
int Data;
Element *nextElement;
Element(int Element) {Data = Element; nextElement = NULL;}
~Element() { }

[Code] ....

I have no errors, but I cannot access the private properties of the class.

The thing I would like to do is: sum the elements of the stack with a friend function.

View 7 Replies View Related

C/C++ :: Print Single Linked List Backward With Functions / Classes - Error Message Regarding Header Files

Oct 11, 2014

I'm trying to print a single linked list backward with functions/classes. I have created the main file and 3 header files. But I'm getting an error on one of the header files, linkedListIterator after adding #include "linkedListType.h". It says that "linkedLlistType.h" is calling itself. And when I try to run it, I get an error of "too many header files." I have tried changing the headers many times, but nothing seems to work.

.cpp file:

/*(Printing a single linked list backward) Include the functions reversePrint and recursiveReversePrint, as discussed in this chapter, in the class linkedListType. Also, write a program function to print a (single) linked list backward. (Use either the class unorderedLinkedList or the class orderedLinkedList to test your function.)*/

#include "linkedListType.h"
#include "orderedLinkedList.h"
#include "linkedListIterator.h"
#include <iostream>
using namespace std;
struct nodeType

[Code] ....

header files:
[URL] .... (error in this header file)
[URL] ....

View 9 Replies View Related

C++ :: Showing Data Added To Classes

Feb 15, 2014

I am new to using classes, and am running into an issue already. I have created the class, and am in the process of adding data to the classes. I have added one piece of data, and now just want to see if I can get it to show in another function, but I am not sure why it is not showing. What about getting the data to show. Then, I will be able to work on adding the rest of the info.

#include <iostream>
#include <cctype>
#include <stdio.h>
#include <stdlib.h>
using namespace std;
//******************************Bill Class**************************
class bill {

[Code] ....

FYI - This is only the relevant code. There is more for this that I have not added.

Error #1: error C2679: binary '<<' : no operator found which takes a right-hand operand of type 'std::string' (or there is no acceptable conversion)

Error #2: error C2679: binary '<<' : no operator found which takes a right-hand operand of type 'std::string' (or there is no acceptable conversion)

View 2 Replies View Related

C++ :: Why Projects Always Roll Their Own Data Structures / Utility Classes

Jun 9, 2014

Why certain projects always roll their own data structures/utililiy classes rather than using the C++ standard libraries? such as linked lists and queues? Is there a particular reason for this?

View 11 Replies View Related

C++ :: Read Data From A File Then Store / Search And Display Using Classes And Arrays

Apr 12, 2013

A company uses two text files: one to store employees' details and another to log their sign in/out time.

The details file - called details.txt" has the following format: ID, Name, Date of Birth, SSN, Department, Position - separated by spaces.

An extract from the file looks like this:

10 alice 4/23/1972 123-45-6789 support assistant
3 bob 6/7/1980 111-12-1134 logistics manager
1 carol 10/2/1963 987-123-1143 admin ceo
2 dave 10/3/1974 902-22-8914 admin cfo
17 erin 6/13/1991 126-83-1942 technology supervisor
15 frank 2/22/1987 303-12-1122 logistics assistant

"timelog.txt" contains daily logs of when employees arrive and leave. It has the following format: ID, Date, Arrival Time, Departure Time - separated by spaces. An extract from the file looks like this:

10 2/11 0900 1700
3 2/11 0930 1730
1 2/11 1100 2000
2 2/11 1000 1530
17 2/11 0900 1700
10 2/12 1000 1830
3 2/12 0930 1730
1 2/12 1100 1900
2 2/12 1030 2000
17 2/12 0900 1700
15 2/12 1100 1600

I have to write a program that searches for specific records using some search parameter, and displays them. Ok first i have to read the data from the files and store them. this is what i have so far....

#include <iostream> //Accesses libaries for console input and output
#include <fstream> //Needed to access the fstream object to read files
#include <string> //Needed to access the string class
#include <cstdlib>

[Code] ....

I know my class and array code is totally wrong i dont know how to store the data for the info is in integer and string form... do i use strings, arrays?

View 1 Replies View Related

C++ :: Does Prototype Of Friend Function Has No Value?

Mar 30, 2013

[URL] ..... Prototype is commented.

[URL] ..... Prototype is included.

both give the correct output. Why?

View 2 Replies View Related

C++ :: WHILE Loop Error / In Streaming Data File (with Functions)

Nov 2, 2014

I have a working lab project with a loop error. Code posted in second post. Here's the requirements:

*
- program has to be able to handle file failure
- must loop (prefer to use a while loop here), read in the data, calculates values, etc. and then output the results.

*
The input data file includes

1. a 1 or a 0 indicating that there is a set of employee data following

2. the hourly rate of the employee

3. the humber of hours worked

4. the number of dependents

5. a 1 or a 0 indicating whether the employee is full time (1=full time).

Problem: At first I wouldn't loop back... so I moved the curly brace above the return0;

View 2 Replies View Related

C++ :: Class Template Friend Operators

Sep 19, 2013

The code below doesn't compile. Two things to clear up:

1) I know x is going to be garbage.
2) I used the same type name label ElementType.

#include <iostream>
#include <ostream>
template <typename ElementType>
class Example {

[Code] .....

View 3 Replies View Related

C++ ::  Operator Overloading Using A Friend Function

Jul 24, 2013

What is the role of friend function in this program? Is it even executed here?

#include <iostream>
using namespace std;
class loc {
int longitude, latitude;
public:
loc() {} // needed to construct temporaries

[Code] ....

View 2 Replies View Related

C++ :: Friend Of Nested Template Class

Nov 9, 2013

Consider the following program below, which compiles without a hitch on MinGW GCC 4.8.1:

template <typename T>
class Outer {
class Nested1 {};
template <typename U>
class Nested2

[Code] .....

Is there any way I can move the definition of func outside of the class?

View 1 Replies View Related

C++ :: How To Specialize Template Friend Operator

Jul 13, 2012

Can't quite seem to get this figured out...

Code:
template <typename T>
class Foo {
public:
Foo(const T& t) :
t(t)

[Code] ....

I can't provide a generic implementation of the << operator, it depends on the specific types of T. So how do I specialize the operator for a specific type T ?

View 5 Replies View Related

C++ :: Widget That Implement Some Matrix Functions Using Data From A Text File

Dec 3, 2014

I need to write a widget that will implement some matrix functions using data from a text file. The input data will be spreadsheet like and fully determined with complete rows and columns. I need to do the following,

1. populate a data structure with the input data (double) to create matrix x
2. transpose the input data matrix x to create x'
3. multiply x * x' to create a square matrix x'x
4. take the determinant of x'x

This is pretty standard linear algebra, but not something I have done in cpp before. Implementation such as the best data types to use to store each of the three matrices, how they are sized, and what library functions may be available for the matrix functions like transpose, multiply, determinant, etc.

I will be removing each data row from the initial input to observe the effect on the determinant in case that has any effect on program design.

View 5 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++ ::  Friend Function Can't Able To Access Private Member

Jan 21, 2015

Am trying to write table object into file. Here's the source code

.hpp file

class Table {
private:
int table_no;
std::string table_type;
bool engaged;
std::time_t start_time;
double total_sec;

[Code] ....

When i compile the above code i get the following error...

table.hpp: In function ‘std::ifstream& operator>>(std::ifstream&, Table&)’:
table.hpp:19:7: error: ‘int Table::table_no’ is private
table.cpp:91:12: error: within this context
table.hpp:20:15: error: ‘std::string Table::table_type’ is private
table.cpp:92:12: error: within this context ...........

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







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