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.
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
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?
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?
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
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)
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 ?
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 ...........
#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.
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++
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 .....
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.
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;
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 (*)()'
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?