473,383 Members | 1,813 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,383 software developers and data experts.

'access private member' error

Hi, all~ ^^

If i use #1 OK, but use # 2 error happend what's different?

#include <iostream>
/* -----------# 1------------
using std::endl;
using std::cout;
using std::ostream;
*/------------------------------

//-------------# 2--------------
using namespace std; //error!!! ' x' : cannot access private member
declared in class 'Point'

class Point
{
private:
int x;
public:
Point(int _x=0):x(_x){}
friend ostream& operator<<(ostream& os, const Point& p);
};

ostream& operator<<(ostream& os, const Point& p)
{
os<<"["<<p.x<<"]"<<endl;
return os;
}

int main(void)
{
Point p;
cout << p;
return 0;
}
Dec 1 '07 #1
4 1874
An********@gmail.com wrote:
Hi, all~ ^^

If i use #1 OK, but use # 2 error happend what's different?

#include <iostream>
/* -----------# 1------------
using std::endl;
using std::cout;
using std::ostream;
*/------------------------------

//-------------# 2--------------
using namespace std; //error!!! ' x' : cannot access private member
declared in class 'Point'
Are you sure? There doesn't look to be anything wrong with the code
(except the indentation!)

Which compiler, where exactly is the error?

<snip>

--
Ian Collins.
Dec 1 '07 #2
tool is MS visual studio c++ 6.0

error message

Compiling...
test2.cpp
test2.cpp(20) : error C2248: 'x' : cannot access private member
declared in class 'Point'
test2.cpp(12) : see declaration of 'x'
test2.cpp(27) : error C2593: 'operator <<' is ambiguous
Error executing cl.exe.
Dec 1 '07 #3
An********@gmail.com wrote:
tool is MS visual studio c++ 6.0
That's probably your problem, upgrade to a decent compiler. Or dop all
the using nonsense and qualify the names.
error message

Compiling...
test2.cpp
test2.cpp(20) : error C2248: 'x' : cannot access private member
declared in class 'Point'
test2.cpp(12) : see declaration of 'x'
test2.cpp(27) : error C2593: 'operator <<' is ambiguous
Being an old compiler, its library probably has ostream outside of the
std namespace as well as inside.

--
Ian Collins.
Dec 1 '07 #4
I did on Linux C++ compiler.

Good~! no error. ^^

Thank you~
Dec 1 '07 #5

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

Similar topics

2
by: diadia | last post by:
when i write two classes as follow . compiler tell me that i can't access private number from other class but if types of two classes are the same it don't have error message ? why? class...
11
by: Roger Leigh | last post by:
The C++ book I have to hand (Liberty and Horvath, Teach yourself C++ for Linux in 21 Days--I know there are better) states that "static member functions cannot access any non-static member...
3
by: mshetty | last post by:
Hi, I have a class x with two public methods xmethod1 and xmethod2. I want to derive a class y such that it can access only xmethod2. I have done the following and it compiles please let me know...
3
by: Random Person | last post by:
Does anyone know how to use VBA to relink tables between two MS Access databases? We have two databases, one with VBA code and the other with data tables. The tables are referenced by linked...
6
by: Peter Frost | last post by:
Please help I don't know if this is possible but what I would really like to do is to use On Error Goto to capture the code that is being executed when an error occurs. Any help would be much...
7
by: dog | last post by:
I've seen plenty of articles on this topic but none of them have been able to solve my problem. I am working with an Access 97 database on an NT4.0 machine, which has many Access reports. I...
3
by: Jorge Cecílio | last post by:
Hi! I would like to export some MS-Access reports output to pdf. However, the only possibility offered by Access (afaik) for me to export formatted output is snp (snapshot) (I use MS-Office...
11
by: Grasshopper | last post by:
Hi, I am automating Access reports to PDF using PDF Writer 6.0. I've created a DTS package to run the reports and schedule a job to run this DTS package. If I PC Anywhere into the server on...
9
by: Mike | last post by:
Hi, Just a simple question: why the compiler doesn't report error when accessing a private member function inside a function having template type ? For example: #include<iostream> using...
15
by: =?Utf-8?B?R2Vvcmdl?= | last post by:
Hello everyone, I met with a strange issue that derived class function can not access base class's protected member. Do you know why? Here is the error message and code. error C2248:...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
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: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
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: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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.