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


ADVERTISEMENT

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++ :: 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 View Related

C++ :: Using Namespaces In Header Files

Dec 9, 2013

So I've been making a header file and put variables in their own namespace to avoid conflicts. My question is, do functions in the header file normally go in a namespace too, or should they just be named in a way which makes them unlikely to be accidentally copied?

View 15 Replies View Related

C++ :: Static Classes Vs Namespaces?

Jan 9, 2014

so i was trying to find out how to do unbuffered input in linux and came across this class: [URL] . i didnt like how i had to create a new instance of it each time i wanted to use it, so i made the functions static and renamed the class to Buffer. i could then call it like this: Buffer::On(); Buffer::Off();. My question is, when doing something like that where the class consists of two functions that can exist indepently of another, which is better: a class like what i did or wrapping it in a namespace?

View 3 Replies View Related

C++ :: Looking For Standard Namespaces Inside Own Files

Sep 2, 2013

This has never happened before but I imagine that I've somehow accidently disabled a library or such.

namespace SB{
namespace Data{
class DLL Filed abstract{
//DLL is a macro defined as either __declspec(dllexport) or __declspec(dllimport)
//depending on whether this is open as a project or a header

[Code]....

The error is from intellisense and is present on every occurrence of std::string

View 14 Replies View Related

C Sharp :: Remove Namespaces In XMLs?

Oct 21, 2012

I need to remove all namespaces from xml file shown after c sharp code (also been attached). The problem is that I am getting the following error being returned by one of the functions

{System.Xml.XmlException: The prefix '' cannot be redefined from '' to 'http://sample.response.power.core.com' within the same start element tag.
at System.Xml.XmlWellFormedWriter.PushNamespaceExplic it(String prefix, String ns)
at System.Xml.XmlWellFormedWriter.WriteEndAttribute()
at System.Xml.Linq.ElementWriter.WriteStartElement(XE lement e)

[Code]....

View 2 Replies View Related

C++ :: Termination Of Namespaces With A Closing Brace Only

Jan 9, 2014

... and not with a brace followed by a semicolon like in class-definitions - reason for that?

View 2 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++ :: 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++ :: Can A Friend Function Work For Two Classes?

Mar 23, 2013

If yes then how?

View 6 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++ ::  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

C/C++ :: Overload Operator With Friend Function Using Constructors

Dec 26, 2014

I want to overload prefix and postfix increment(++) operators with friend function. I also have to use the constructors for this. How can I do this? in C++

View 4 Replies View Related

Visual C++ :: Friend Class And Pointer Function

Mar 9, 2013

I need understanding this block of code, particularly this line : *getLeftChild() { return this - _child; }

Code:

public class UpperNode {
BOX _box;
int _child;
FORCEINLINE UpperNode *getLeftChild() { return this - _child; }
...
};

Here I have this function:

Code:
void
UpperNode::visulization(int level) {
if (isLeaf())
_box.visulization();
else
if ((level > 0)) {

[Code] .....

It also makes calls for "getLeftChild()";

But I see that getLeftChild expects function pointer, and I absolutely have no clue where "this" comes from inside function body.

(return this - _child) - "this" has to be integer.

Or, if we gave pointer, and "this" is referring to some UpperNode, then I can't understand to which one, I have no UpperNode array defined or something. So if this functions is actually scaling pointer address, then scaling where to? I could comprehend it, if I had some array of UpperNodes, but not just class. I have UpperNodes array defined in other friendly class, but don't think they are related .....

View 2 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 / Classes - Perform Operator Overload With Insertion Operator

Mar 22, 2013

I'm doing a refresher for C++ and have gotten to operator overloading. I'm trying to perform an operator overload with the insertion (<<) operator, but I have encountered a problem.

Here's my class [In a header file "Shinigami.h"]

#include<string>
namespace K{
class Quincy;
class Shinigami{
friend std::ostream& operator<<(std::ostream&, const Shinigami&);

[Code] .....

If the operator function is a friend of the 'Shinigami' class, why doesn't it recognize any of it's private members? I need it to be in this file because I'm doing a bit of association with the 'Quincy' class.

I thought it was the namespace, but I included that.

View 9 Replies View Related

C/C++ :: How To Access Linked List Functions From Stack Class Without Functions

Mar 20, 2014

I'm a little confused by my programming assignment this week. I've been working at it Wednesday and I've made progress but I'm still confused as to how I'm supposed to do this. The class I made is called Stack, and it's derived from a template class called StackADT. We also utilize a class called unorderedLinkedList, which is derived from a class called linkedList.

We're supposed to implement all of the virtual functions from stackADT in the Stack class. The Stack data is stored in a an unorderedLinkedList, so what I'm confused by is how to implement a few of the Stack functions because there are no functions in unorderedLinkedList which we could call to manipulate the data.

As you can see from my attached code, I'm really confused by how I'm supposed to implement the pop() and top() functions, and I also think my initializeList() function is wrong. We don't have any similar functions in unorderedLinkedList to call, so I'm at a loss of how i'd access my unorderedLinkedList. My initial thought was to call the similar functions in the class that unorderedLinkedList was derived from, linkedList, but I'm unsure of this is what we're supposed to do, or if theres actually a way to access my unorderedLinkedList without having to use the functions from the base class.

NOTE: We're not allowed to modify stackADT, unorderedLinkedList, and linkedList.

Stack.h

#include "stackADT.h"
#include "unorderedLinkedList.h"
template<class Type>
class Stack: public stackADT<Type>{
template <class T>
struct nodeType
{
T info;
nodeType<T> *link;

[Code]...

View 3 Replies View Related

C/C++ :: Array Of Functions Pointing To In Class Functions With Arduino

May 3, 2013

At the moment im trying out with pointing to an array of functions. I got this working as following:

typedef void (* functionPtr) ();  
functionPtr functions[2][2]={{do11,do12}, {do21,do22}};    
void do11(){DEBUG_PRINTLN("11");}
void do12(){DEBUG_PRINTLN("12");}
void do21(){DEBUG_PRINTLN("21");}
void do22(){DEBUG_PRINTLN("22");}    
void loop(){
         A=0;
         B=1;
         functions[A][b]();
}  

But now I'm trying to use this to point to a function inside a class so instead of do11, i want to be able to point to Basic.Do11. Somehow this doesnt work and I keep on getting this message:

error: argument of type 'void (Basic::)()' does not match 'void (*)()'

View 2 Replies View Related

C :: Getting Used To Functions

Jul 24, 2013

So In my studying of C I am starting to come across more programs with functions in them.This particular program asks for two numbers, and calculates the sum of all the squares of the two numbers and the numbers in between them. I am confused about the get_int() function.

Code:

/* checking.c -- validating input */
#include <stdio.h>
#include <stdbool.h>
int get_int(void); // validate that input is an integer
bool bad_limits(int begin, int end, int low, int high); // validate that range limits are valid
double sum_squares(int a, int b); // calculate the sum of the squares of the integers a through b
}

[code]....

So in that get_int() function, it's pretty simple if scanf returns 1, otherwise... another while loop call the getchar() function, which is assigned to the variable ch. So say I enter 'a' for the lower limit, this is what happens:

Code: Enter the limits (enter 0 for both limits to quit):
lower limit: a

a is not an integer. It seems as if getchar() somehow "got the character" from scanf(). There's no way that getchar() could have been simultaneously reading my input, because that function is not even called until scanf has already not returned 1. So I'm confused how that happened. I was under the impression that getchar() got input from the keyboard, which would lead me to think that I would be prompted to input something again when getchar() is called, before putchar() prints the scanf input. But this is obviously not the case.

Also, I'm curious about that comment beside putchar(ch) that says //dispose of bad input. I recall a long time ago on these forums, someone told me something about how once scanf has read input, that input is like... stuck to scanf.. So does putchar() not only print the input from scanf/getchar, but also unload it from scanf, so to speak?

View 4 Replies View Related

C++ :: Get And Set Functions

Feb 1, 2014

i'm stuck with functions

#include <iostream>
#include <functional>
using namespace std;
template <typename T>
class property

[code].....

the code works like a charm. but imagine that i need more with Get and Set functions, how can i connect them to the T PropertyValue on class property?

View 12 Replies View Related

C++ :: How To Get A Set Of Functions To All Use The Same Template

Dec 11, 2013

I'm getting tired of writing Code: template <typename T> everywhere.

Is the only solution to encapsulate all my desired functions in a templated class?

View 7 Replies View Related







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