Category : friend-function

Consider this example: #include <type_traits> class C { }; struct S { friend std::true_type f(C&) { return std::true_type(); } }; std::false_type f(C&); int main() { C c; return decltype(f(c))::value; } If I compile it, I get: <source>:10:17: error: functions that differ only in their return type cannot be overloaded However, if I comment out std::false_type ..

Read more

I am trying to pass array of object in friend function. dut it shows undefined structure ‘Directory’. And also can we use private data members in friend function. Because if I create Private: char name[30]; It shows error ‘Directory::name’ not accessible. #include<conio.h> #include<iostream.h> #include<string.h> #include<stdlib.h> class Directory { private: char phone_no[11]; // char name[30]; public: ..

Read more

the statement below the function calling is not executed. i am at a loss, why this is so? could someone please clarify. Please consider the code below : #include<iostream> #include<cmath> using namespace std; class Matrix { private: int row,col; double *values; public: Matrix(); Matrix(int r, int c, double* x); void setdim(int m, int n){row=m;col=n;} int ..

Read more

Here , I wrote a code implementing addition operations on a Sparse Matrix using member function operator of a class . Now while the input functions work fine . The addtion function shows error with normal elements but works fine with diagonal elements . and the elements in the first row . I have pasted ..

Read more

I’ve tried for weeks and searched for days for an awnser, but haven’t found it. My code is rather large and intertwined, but my problem is with 3 functions/classes, therefore i will only show my declarations and relevant information. I have the following non-compilable code: class Word{ private: *members* public: //friend declaration so i could ..

Read more

I am trying use a friend function. The function should be a friend to all the classes that i have. But i get multiple errors some of which says incomplete type. The following are files that i have: main.cpp #include <iostream> #include "my_ClassA.h" #include "my_ClassB.h" #include "my_ClassC.h" #include "my_ClassD.h" int main() { std::cout<<"Hello World"; my_namespace::my_ClassA ..

Read more