Hi All, in below class i wanted to have two friend function(overloading) one with default argument and other is without default argument. but during compilation it gives error. could you let me know how to fix (overload) this by not changing the function name , argument type or number of arguments. **error:** warning: void fun(int, int, int) is already a friend of class foo #include<iostream> using namespace std; class foo { public: friend void fun (int a, int b, int c); friend void fun (int a, int b, int c=20); }; int main() { return 1; }

Member Avatar
Member Avatar
+0 forum 1

Need help to fix errors, I know int a[] should be specified but not sure how to. #include <iostream> using namespace std; class TWO { private: int age[5]; public: //read data into array void ReadData(int age[], int n); //member to return the average of data in array age of object p friend int FindAverage(TWO p); //member to find and return the max and min age void FindMaxMin(int &maxAge, int& minAge, int age[], int n); //display ages > age average void DisplayAboveAverage(int ageAve, int age[], int n); //display the max and min ages void DisplayMaxMinAge(int maxAge, int minAge, int age[], int …

Member Avatar
Member Avatar
+0 forum 2

http://s11.postimg.org/kxl3cemw3/error.png this is the least error that I can get from multiple time of debugging. [TheCodeFile](http://www.fast-files.com/getfile.aspx?file=70535) StrBlob.h has needed to use something from StrBlobPtr.h and StrBlobPtr.h needed to use something from StrBlob.h I did tried to #include each file on each other respectively, but ofcourse that would be a data structure error(that can't be fixed) due to infinite recurssion. so what should I do to fix this? P.S. the code is purely come from a c++ tutorial book "C++ Primer 5th edition". Yet, the exercise did tell to add there appropriate friend declaration, but I did all of them, the …

Member Avatar
Member Avatar
+0 forum 6

Hello guys, I am doing a Friend system on my website, and I did the friend request, to accept, but the friends list isn't alright in some part of code because it isn't take the correct id, anyone can help me? 1. <?php 2. 3. $users = $_SESSION['username']; 4. 5. $connect = mysql_connect("localhost","root","") or die(mysql_error()); 6. mysql_select_db("website"); 7. 8. $user = $_GET['u']; 9. 10. $sql = mysql_query ("SELECT * FROM users"); 11. 12. $result = mysql_fetch_assoc($sql); 13. 14. 15. $id3 = $result['id']; 16. 17. 18. $selusers = mysql_query("SELECT * FROM u_friends WHERE friend='$users' OR username='$users'"); 19. 20. $row = mysql_num_rows($selusers); …

Member Avatar
Member Avatar
+0 forum 5

#include <iostream> using namespace std; template<class T> class MyClass { private: T data; public: MyClass(T data) { this->data = data; } }; template<class T> bool operator< (const MyClass<T> & a, const MyClass<T> & b) { return (a.data < b.data); } int main() { MyClass<int> x(1); MyClass<int> y(2); if(x < y) cout << "x is less than y!" << endl; return 0; } when i compile this it says T data is private, i know i needa declare some friend operators but not really sure how to do it :( can anyone help me please??

Member Avatar
Member Avatar
+0 forum 3

#include <string> #include <iostream> #ifndef NAME_H #define NAME_H class Name { private: std::string first_,last_ ; public: explicit Name(const std::string & first = "john", const std::string & last = "doc"):first_(first),last_(last) { if(!isvalidlast(last_) || isvalidfirst(first_)) throw "Name :: Name(const string &,const string &):invalid Name"; } static bool isvalidlast(const std::string & last){} static bool isvalidfirst(const std::string & first){} std::string getfirst() const { return first_; } bool setfirst (const std::string & first) { if(!isvalidfirst(first)) return false; first_=first; return true; } friend std::istream & operator >> (std::istream &,Name &); friend std::ostream & operator <<(std::ostream &,Name &); }; //end of class defn inline std::ostream & operator …

Member Avatar
Member Avatar
+0 forum 6

Hi , I am just curious to know that , why i am not able to compile below code if i define access function inside the class. i am able to execute another friend function inside the class. Does it mean class scope is responsible for the execution of other friend function or due to having global scope it execute code oustside class. #include<iostream> #include<memory> #include<process.h> using namespace std; class a { int i; public: void display () { cout<<"Hello"; } /*friend void access();*/ friend void access() { a x; x.i=10; cout<<x.i; } /* friend void access(a & x) works …

Member Avatar
Member Avatar
+0 forum 2

hai

Member Avatar
Member Avatar
+0 forum 1

Hi, Is there any way to not allow private construction in friend function, In case we do have private constructor with friend function in our class.Only Static method should be responsible for object creation and other than this compiler should flash error message. #include<iostream> #include<memory> using namespace std; class a { public: void see () { cout<<"Motimaa"; } static a& getinstance() { static a instance; return instance; } private: a() {}; friend void access(); }; void access () { a obj; obj.see();//still friend function can access } int main() { a::getinstance().see(); access(); return 1; }

Member Avatar
Member Avatar
+0 forum 4

Facebook sometimes suggests people with whom I can connect. Some of them are old contacts from high school. However, the odd time I wonder if I have already sent them a friend request, which they have ignored. My question: Is there a way to tell if I have previously sent a person a friend request? I have gone through several of the options and menus, but I can't find this capability. Am I missing something? In LinkedIn, I can go to my Connections and see that I have X number of outstanding invitations. (Okay, fine, some of these people were …

Member Avatar
Member Avatar
+0 forum 1

Essentially I have two header files, one called 'ACYDTypes.h' that contains the classes for the basic types of this system and the other called 'Settings.h' that contains function for general settings. In the Settings.h file, there is a namespace called 'Ac_Type_Settings', and within that is a class called 'AcTypeSettings'. This contains changeable static variables of settings that will affect the classes in the 'ACYDTypes.h'. I have made all the classes in 'ACYDTypes.h' a friend of this class so that my system's basic types can directly access varible settings affecting them, rather than having to call a public function from the …

Member Avatar
Member Avatar
+0 forum 1

Inside FileTwo.h #ifndef FILETWO #define FILETWO #include"FileOne.h" class FileOne ; class FileTwo { public: int Test(FileOne One){ return (One.var1+One.var2);} FileTwo(void); ~FileTwo(void); }; #endif Inside FileOne.h #ifndef FILEONE #define FILEONE #include"FileTwo.h" class FileTwo ; class FileOne { private: int var1 , var2 , var3 ; public : friend int FileTwo::Test(FileOne One); FileOne(){ var1= 12;var2 = 24; } }; #endif Inside main.cpp #include<iostream> using namespace std ; #include"FileOne.h" #include"FileTwo.h" int main(){ FileOne one ; FileTo two ; cout<<two.Test(one); } During compilation i got the following error 1-- error C2027: use of undefined type 'FileOne' c:\users\e543925\documents\visual studio 2005\projects\myproject\filetwo.h 2--error C2027: use of undefined …

Member Avatar
Member Avatar
+0 forum 5

How to Promote my profile free in this website

Member Avatar
Member Avatar
+0 forum 17

Hello, I have been given a class diagram where a variable called light_years must be a const int and stored in the space class, but later on that value must be used in the main file. Below is the space class class space { private: static const int LIGHT_YEARS; public: // -Many functions are here- }; I need to access the value here #include "stdafx.h" #include <iostream> #include "Space.h" int _tmain(int argc, _TCHAR* argv[]) { for (int i=0; i<3; i++) { 8*LIGHT_YEARS; // I've tried 8*Space::LIGHT_YEARS; } system("pause"); return 0; } Is there someway to friend the main function or …

Member Avatar
Member Avatar
+0 forum 3

matrix multiplication program

Member Avatar
Member Avatar
-1 forum 2

Hi friends! i'm currently work on a chatting system that requires me to list all the user friends, so i need a code that will help me navigate throw the freinds list one after the other. thanks!

Member Avatar
Member Avatar
+0 forum 3

Hello, after I have friendet my class to "<" operator it dosn't work after i use sort over an vector of class instances it does nothing: class + main : class RAngle{ public: int x,y,l; RAngle(){ } RAngle(int i,int j,int k){ x=i,y=j,l=k; } bool operator<(const RAngle& rhs)const { if(l < rhs.l){ return true; } return 0; } friend ostream& operator << (ostream& out, const RAngle& ra){ out << ra.x << " " << ra.y << " " << ra.l <<endl; return out; } friend istream& operator >>( istream& is, RAngle &ra) { is >> ra.x; is >> ra.y; is >> …

Member Avatar
Member Avatar
+0 forum 8

Hi all, I am doing some c++ exercise about operator replacing. I have successfully replaced the + (plus) operator to work on a user-defined class. I understand these operators are order-sensitive: need to replace the operator for (class+int) and for (int+class). Thus, creating **two** replacements that do exactly the same. My question is: can I have replacement2 execute replacement1 and return the result? This would have the advantage of 1) shorter code 2) no unnecessary repeats in code. If I need to change the way I do the replacements I'll need to worry about it only once. Here's a sample …

Member Avatar
+0 forum 0

Hi guys, I'm learning C++ from a book and I have a question about defining unary operators: In the book I'm working with there's an example, where they define a class called point, and define ++ operator for point *as friend*. here's the example: ~~~ c class point { int a,b; public: point(){}; point(int Ia, int Ib) {a=Ia; b=Ib;} friend point operator++(point &p1); }; point operator++(point &p1) { p1.a++; p1.b++; return p1; } ~~~ The book goes on to state that when doing this we must send the object by reference, or else the function will not change the original …

Member Avatar
Member Avatar
+0 forum 2

Hey guys, i am a beginner in c++ and i don't know what's wrong with my code. i'dont get any errors, but when i run the programme the following: "... Line: 251 Expression: vector iterators incompatible ..." I think there is a problem with "b.getmark()" and "b.getcoursename()" but i don't know how to solve it since i cannot use "coursename" or "mark" instead Thanks in advance, guys. I hope someone can help me! My code looks a little bit strange cos some parts are not displayed properly... strangely the problematic parts. Sorry about that. This is my code: #include <iostream> …

Member Avatar
Member Avatar
+0 forum 5

Hello I am trying to make a friend request system and I have it so it displays all the friend request and at the end there is a button that says "Yes" and one that says "No" I would like the Yes button to change "0" to "1" and No to change "0" to "2" in the friend request table. So if you had multiple friend request I would like it to be displayed as John Smith - [Yes] - [No] Sam Young - [Yes] - [No] Mary Berry - [Yes] - [No] I would like it so you can …

Member Avatar
+0 forum 0

I have a class that looks like this [CODE] //the mem_data class======================================// class mem_data { public: mem_data(int,int,std::string); ~mem_data(); private: std::vector<reader> mem_store; int complete; friend class model_base; }; [/CODE] Now, I would like to let the class model_base access mem_store My main code will contain the following: [CODE] mem_data test_data(20110601,10,"test_file.csv"); model_base test_model(); [/CODE] I basically want test_model to have access to mem_store of test_data. How can I go about writing model_base to accomplish this? So far, I have [CODE] //the MODEL_BASE class======================================// class model_base { public: model_base(); ~model_base(); private: mem_data *pass; }; [/CODE] I want to somehow pass the address of …

Member Avatar
Member Avatar
+0 forum 3

Hi guys, I'm new in C++ and I tried to compile the attached code without success. This is the output when using g++ under Ubuntu system /src$ g++ -c -Wno-deprecated -I../include Options.C Options.C: In constructor ‘Options::Options(const char*)’: Options.C:13: error: ‘parsequestion’ was not declared in this scope I tried several modifications but I did not achieve any solution. Please, could you help me on this? I do not know whether the problem is the code or the compiler ... Thanks in advance

Member Avatar
+0 forum 0

can you help me please ... first I can't find my subject which I post it in your web second I want some help to use this web 3rd I want you help me if you can

Member Avatar
Member Avatar
+0 forum 3

Ok, so im trying to make my sister a flashcards program with dev c++. What you do is put in the deck name and how many cards you want. Then you go through for each card and put in what's on the front and back. I also want it so you can go back in later and access that deck again. I also want it to have graphics and text input boxes, not the boring black box. It would be grand if you could give me a very rough block of code for it. Thanks!

Member Avatar
Member Avatar
+0 forum 20

Hi friends, I was understanding the concept of friend functions. I read in my book that there are two possible ways of "making friendship":cool: 1. Make a class a friend. 2. Make the method in a class a friend. I am able to write a code for the first point. But when I tried the second one, I got the error as said in the title. Here is my piece of code. To make this less lengthier I have put .h and .cpp file in one code block. [CODE] /****************** MyClass.h ***************/ #ifndef MYCLASS_H #define MYCLASS_H class MyClass { public: …

Member Avatar
Member Avatar
+0 forum 17

Im getting the folowing error while trying to implement a friend function between two classes. "Board.C: In member function ‘void Board::input(bool)’: Board.C:227: error: ‘class Piece’ has no member named ‘castSpell’ make: *** [Board.o] Error 1" Piece's Header file [CODE] #ifndef PIECE_H #define PIECE_H # include "Spellcaster.h" # include <iostream> #include <string> #include<cmath> using namespace std; class Board; class Piece { public: string name; bool Player; Piece(); ~Piece(){}; virtual bool validMove (int,int)=0; virtual void move (int x, int y ){}; string symbol; int xPos; int yPos; void setLife(int); int getLife(); void Select(); void takeDamage(int); bool caster; bool secondaryAction; friend void Spellcaster::castSpell(); …

Member Avatar
Member Avatar
+0 forum 9

Hi everyone I am trying to develop a friend system where you can view friends who you are friends with. I have been able to get it to show one result but it wont show any other. Please can someone tell me what I am doing wrong. Here is the code [CODE]<?php require("check_session.php"); $id = $_SESSION['id']; $username = $_SESSION['username']; ?> Here is a list of your current friends. <br /> <br /> <?php $sql = mysql_query("SELECT * FROM friends WHERE user_id='$id' AND friend='1'"); while($fetch = mysql_fetch_assoc($sql)) { $friend_id = $fetch['friend_id']; } ?> <?php $usertable = mysql_query("SELECT * FROM users WHERE …

Member Avatar
Member Avatar
+0 forum 5

Hi, Recently (today) got an assignment to take a particular code that we've done previously, and split it into 3 files: 2 .cpp files and a header file. Now, i believe i've done it correctly, but the only thing that's throwing up errors is the use of friend for overloading the << operator. Here's how it was used in the previous example (class name is "complex"): [CODE] ...//other class stuff friend ostream & operator<<(ostream &os, const complex &z); }; //end of class ostream & operator<<(ostream &os, const complex &z) { //..stuff... } [/CODE] and I've split the class declaration and …

Member Avatar
Member Avatar
+0 forum 4

I have such a problem: when I write:[code=c++] template<bool b> void foo(void); template<bool b> class B { friend void foo<b>(void); }; template<bool b> void foo(void){}; [/code] everything works just fine. But when I incapsulate all this in another class, I receive errors: [code=c++] struct C { template<bool b> void foo(void); template<bool b> class B { friend void C::foo<b>(void); }; }; template<bool b> void C::foo(void){}; [/code]. In Visual C++ 2008 I get these errors: error C2975: 'b' : invalid template argument for 'C::foo', expected compile-time constant expression; error C2245: non-existent member function 'C::foo' specified as friend (member function signature does not …

Member Avatar
Member Avatar
+1 forum 11

The End.