Click here to Skip to main content
15,919,613 members
Home / Discussions / Managed C++/CLI
   

Managed C++/CLI

 
GeneralRe: why the function didn`t working? Pin
mcnu13-Sep-05 5:54
mcnu13-Sep-05 5:54 
GeneralRe: why the function didn`t working? Pin
Cedric Moonen13-Sep-05 20:24
Cedric Moonen13-Sep-05 20:24 
GeneralRe: why the function didn`t working? Pin
toxcct13-Sep-05 21:12
toxcct13-Sep-05 21:12 
QuestionC1010 Error Pin
cjbaltar12-Sep-05 16:43
cjbaltar12-Sep-05 16:43 
AnswerRe: C1010 Error Pin
Christian Graus12-Sep-05 16:53
protectorChristian Graus12-Sep-05 16:53 
GeneralRe: C1010 Error Pin
cjbaltar12-Sep-05 17:36
cjbaltar12-Sep-05 17:36 
GeneralRe: C1010 Error Pin
Christian Graus12-Sep-05 17:42
protectorChristian Graus12-Sep-05 17:42 
QuestionThree Ques Pin
LiYS12-Sep-05 5:57
LiYS12-Sep-05 5:57 
This is repost If you have seen it, but as I getting clearer as to what the questions this few lines of code have presented, I feel it is necessary to repost it because there's something that I knew the answer which I want to share and of course some I don't know and that's for you.

#include <iostream>
using namespace std;
class A
{
	int i;
public:
	A(int ii = 0) : i (ii){}
	friend A operator+(A& left, A& right)
	{
		return A(left.i + right.i);
	}
	friend A operator-(A& left, A& right)
	{
		return A(left.i - right.i);
	}
	friend ostream& operator << (ostream& os, A a);
};
	ostream& operator << (ostream& os, A a)
	{
		return os << a.i << endl;
	}

int main() 
{
	A a(1), b(2), c(3);
	cout << (a + b);
	cout << (a - b);
 	getchar();
}


First of all I'm under VC++ 6.0

Those questions surround the code above are characterized by the following debug error messages:

1. "fatal error C1001: INTERNAL COMPILER ERROR".
2. "'i' : cannot access private member declared in class 'A'"
3. "'operator <<' is ambiguous"


The one of the resolution for the first one is operator foreward declaration which is pretty clear.

But I'm not clear with the 2, 3. For 3, the following statement is my guess and probably wildest guess, since that's the most logical one I can think of, correct me if I'm wrong. It seems once you move the definition for friend operator "<<" out of the class then the Koenig lookup was applied, because it is an unqualified the function, that was what the theory says(function at file scope fit into the unqualified category?). According to the theory cout << A bring the namespace "class A" into the list for lookup and it's ambiguous against the operator "<<" in <iostream> since "using namespace std" is introduced here? bur for the 2 I don't know why the compiler see friend operator "<<" as a function which has nothing to do with class A, Is there correlation exists between question 2 and 3?

Here the right implementation, at least at the compiler perspective

#include <iostream>
using namespace std;
class A;
A operator +(A& left, A& right);
A operator -(A& left, A& right);class A
{
	int i;
public:
	A(int ii = 0) : i (ii){}
	friend A operator+(A& left, A& right)
	{
		return A(left.i + right.i);
	}
	friend A operator-(A& left, A& right)
	{
		return A(left.i - right.i);
	}
	friend ostream& operator << (ostream& os, A a);
	{
		return os << a.i << endl;
	}};

int main() 
{
	A a(1), b(2), c(3);
	cout << (a + b);
	cout << (a - b);
 	getchar();
}


Probably I'll go to bed with unsolved questions in mind, cuz here's late at night



AnswerRe: Three Ques Pin
Christian Graus12-Sep-05 12:36
protectorChristian Graus12-Sep-05 12:36 
GeneralRe: Three Ques Pin
LiYS12-Sep-05 15:13
LiYS12-Sep-05 15:13 
GeneralRe: Three Ques Pin
Christian Graus12-Sep-05 17:48
protectorChristian Graus12-Sep-05 17:48 
Questionheader error Pin
rolati12-Sep-05 4:08
rolati12-Sep-05 4:08 
QuestionHelp me!!!!! Detecting change in data streams Pin
bulgaa12-Sep-05 3:02
bulgaa12-Sep-05 3:02 
QuestionInsert data problem Pin
mengyin11-Sep-05 22:19
mengyin11-Sep-05 22:19 
Questionclasses c++ project HELP!! PLZ Pin
da_comp_learner11-Sep-05 15:19
da_comp_learner11-Sep-05 15:19 
AnswerRe: classes c++ project HELP!! PLZ Pin
Christian Graus11-Sep-05 15:33
protectorChristian Graus11-Sep-05 15:33 
GeneralRe: classes c++ project HELP!! PLZ Pin
da_comp_learner11-Sep-05 15:41
da_comp_learner11-Sep-05 15:41 
GeneralRe: classes c++ project HELP!! PLZ Pin
Christian Graus11-Sep-05 15:55
protectorChristian Graus11-Sep-05 15:55 
QuestionHelp with DJGPP! (GCC for DOS) Pin
Lord Kixdemp11-Sep-05 7:06
Lord Kixdemp11-Sep-05 7:06 
QuestionRe: Help with DJGPP! (GCC for DOS) Pin
Lord Kixdemp11-Sep-05 11:47
Lord Kixdemp11-Sep-05 11:47 
QuestionMonitor Traffic on Single Computer... Pin
code-frog10-Sep-05 15:24
professionalcode-frog10-Sep-05 15:24 
Questionwhy it is giving runtime error? Pin
mcnu10-Sep-05 7:06
mcnu10-Sep-05 7:06 
AnswerRe: why it is giving runtime error? Pin
Christian Graus11-Sep-05 12:33
protectorChristian Graus11-Sep-05 12:33 
GeneralRe: why it is giving runtime error? Pin
mcnu11-Sep-05 15:45
mcnu11-Sep-05 15:45 
GeneralRe: why it is giving runtime error? Pin
Christian Graus11-Sep-05 15:56
protectorChristian Graus11-Sep-05 15:56 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.