LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 09-26-2010, 12:31 PM   #1
vbx_wx
Member
 
Registered: Feb 2010
Posts: 181

Rep: Reputation: 16
C++ templates


Code:
class Buddy {};

template<class T>
class My {
	int i;
public:
	void play(My<Buddy>& s)
	{
		s.i = 3;
	}
};

int main()
{
	My<int> h;
	My<Buddy> me, bud;
	h.play(bud);
	me.play(bud);
}
Why am I getting this error ?

Code:
error: ‘int My<Buddy>::i’ is private
 
Old 09-26-2010, 01:06 PM   #2
johnsfine
LQ Guru
 
Registered: Dec 2007
Distribution: Centos
Posts: 5,286

Rep: Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197
My<Buddy> and My<int> are two different classes, so a private member of one cannot be accessed by the other.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
C++: using templates Ephracis Programming 2 03-08-2009 01:39 PM
C++ , templates vedanu84 Programming 5 03-11-2008 03:01 PM
c++ templates ashirazi Programming 5 07-30-2004 05:17 AM
C++ and templates The_Nerd Programming 4 06-23-2004 01:15 PM
Templates MGLindsey Linux - Networking 0 07-02-2002 11:12 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 08:36 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration