473,378 Members | 1,138 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

What is wrong with the following program?

I forward declared the class test. But I still get some error. Would
you please help me to find out what is wrong with this program?

Peng

//#include <utility>
#include <iostream>

//using namespace std::rel_ops;

class test;

class const_test{
public:
friend class test;
const_test(const test &t) : _i(t._i){}//error
const_test(int i) : _i(i){}
bool operator == (const const_test& t) const {
return _i == t._i;
}
private:
int _i;
};

class test{
public:
test(int i) : _i(i){}
bool operator == (const const_test& t) const {
return _i == t._i;
}
private:
int _i;
};

int main(){
test t1(1);
test t2(2);
// std::cout << (t1 != t2) << std::endl;
// std::cout << (t1 == t2) << std::endl;
}

Oct 22 '05 #1
1 1542
Pe*******@gmail.com wrote:
I forward declared the class test. But I still get some error. Would
you please help me to find out what is wrong with this program?

Peng

//#include <utility>
#include <iostream>

//using namespace std::rel_ops;

class test;

class const_test{
public:
friend class test;
const_test(const test &t) : _i(t._i){}//error
You're using what to the compiler seems to be a member of 'test',
before defining that class. The compiler cannot generate code
without knowing what 'test' looks like inside. You will need to
move the definition of this c-tor below the 'class test' definition.
const_test(int i) : _i(i){}
bool operator == (const const_test& t) const {
return _i == t._i;
}
private:
int _i;
};

class test{
public:
test(int i) : _i(i){}
bool operator == (const const_test& t) const {
return _i == t._i;
}
private:
int _i;
};

int main(){
test t1(1);
test t2(2);
// std::cout << (t1 != t2) << std::endl;
// std::cout << (t1 == t2) << std::endl;
}


V
Oct 22 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

125
by: Sarah Tanembaum | last post by:
Beside its an opensource and supported by community, what's the fundamental differences between PostgreSQL and those high-price commercial database (and some are bloated such as Oracle) from...
56
by: Cherrish Vaidiyan | last post by:
Frinds, Hope everyone is doing fine.i feel pointers to be the most toughest part in C. i have just completed learning pointers & arrays related portions. I need to attend technical interview on...
51
by: jacob navia | last post by:
I would like to add at the beginning of the C tutorial I am writing a short blurb about what "types" are. I came up with the following text. Please can you comment? Did I miss something? Is...
6
by: alternativa | last post by:
Hi, I have problem with the following function - it was intended to ask a user for a 4-digits number: double ask_for_number (void) { char *notint; char s2; double entered_number;
18
by: ben.carbery | last post by:
Hi, I have just written a simple program to get me started in C that calculates the number of days since your birthdate. One thing that confuses me about the program (even though it works) is...
22
by: noridotjabi | last post by:
Okay. I'm quite embarased to be asking this but I cannot seem to get files to work. I don't know what the problem is. Is there something wrong with this: (file related) #include <stdio.h>...
669
by: Xah Lee | last post by:
in March, i posted a essay “What is Expressiveness in a Computer Language”, archived at: http://xahlee.org/perl-python/what_is_expresiveness.html I was informed then that there is a academic...
5
by: Ryan | last post by:
{"POINTID":77902,"MAPID":762,"LONG":-122.21654892,"LAT":"37.1834331019","CITY":"Boulder Creek","STATE":"CA","DIST":5745.4} I get an "invalid label" error... I'm kinda new to this. Thanks!
7
by: Sunil Korah | last post by:
Hi, I haven't used access reports much. I have a problem in getting the total of a group. I have 3 fields, ProgName (Program name), Pname (Participant's name) and PCategory (Participant...
16
by: chutsu | last post by:
Ok Here is a problem, I got a imaginary database program that I need to code, to add a patient I have function inser_patient. but when I try to input the details it doesn't quite work the way I...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.