[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

Compiling Error VS2010

Posted on 2010-09-22
10
Medium Priority
?
440 Views
Last Modified: 2012-05-10
Hi,

I am the beginner of Visual C++(2010), I got the compiling errors
from this attached code.

Please give me advice.
Thanks,
JT
#include "stdafx.h"
#include <iostream>

using namespace std;

class A
{
public:
	int x,y,z;
	A(int a, int b, int c) { x=a; y=b; z=c;}

}

ostream &operator<<(ostream &stream, A o)
{
	stream << o.x << ",";
	stream << o.y << ",";
	stream << o.z << endl;

}

using namespace System;

int main(array<System::String ^> ^args)
{
    //Console::WriteLine(L"Hello World");
    A a(1,2,3), b(2,3,4), c(5,6,7);
	cout << a << b << c;
    return 0;
}

Open in new window

0
Comment
Question by:jtran007
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
  • 3
10 Comments
 
LVL 32

Expert Comment

by:phoffric
ID: 33740316
Could you list the errors with the line numbers?
0
 
LVL 32

Expert Comment

by:phoffric
ID: 33740323
I'm not sure what System namespace is. AFIK for your includes, line 4 should be good.
0
 
LVL 86

Expert Comment

by:jkr
ID: 33740512
The C++ part has a few problems nin terms of syntax and declaration of such an operator, the following works fine:
#include <iostream>

using namespace std;

class A;

ostream& operator<<(ostream &stream, A& o);

class A
{
friend ostream& operator<<(ostream &stream, A& o);
public:
	int x,y,z;
	A(int a, int b, int c) { x=a; y=b; z=c;}

};

ostream& operator<<(ostream &stream, A& o)
{
	stream << o.x << ",";
	stream << o.y << ",";
	stream << o.z << endl;

}


int main()
{

    A a(1,2,3), b(2,3,4), c(5,6,7);
	cout << a << b << c;
    return 0;
}

Open in new window

0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 86

Expert Comment

by:jkr
ID: 33740520
Ooops, sorry, little correction:
#include <iostream>

using namespace std;

class A;

ostream& operator<<(ostream &stream, A& o);

class A
{
friend ostream& operator<<(ostream &stream, A& o);
public:
	int x,y,z;
	A(int a, int b, int c) { x=a; y=b; z=c;}

};

ostream& operator<<(ostream &stream, A& o)
{
	stream << o.x << ",";
	stream << o.y << ",";
	stream << o.z << endl;

   return stream;

}


int main()
{
    A a(1,2,3), b(2,3,4), c(5,6,7);
	cout << a << b << c;
    return 0;
}

Open in new window

0
 
LVL 32

Assisted Solution

by:phoffric
phoffric earned 200 total points
ID: 33740543
I thought the author just wanted advice in order to learn.
0
 

Author Comment

by:jtran007
ID: 33740833
Hi,

Thanks jkr. You are ringt; however, I'd like this code running under VS2010 for c++ since
once I chose the console project, the Visual studio automatically adds "using namespace System"
and int main(array<System::String ^> ^args).
How is this code modified to work in this vs2010 environment but still keeps the same function call?

Thanks again,
JT
0
 
LVL 86

Expert Comment

by:jkr
ID: 33740924
You mean the following?
int main(int argc, char** argv)
{
    A a(1,2,3), b(2,3,4), c(5,6,7);
	cout << a << b << c;
    return 0;
}

Open in new window

0
 

Author Comment

by:jtran007
ID: 33746066
Hi jkr,

I mean this call which is autmatically added by VS2010 when the console app is chosen:

int main(array<System::String ^> ^args)

Do you have any idea since it is totally different from the one (int main(int argc, char** argv)
that I usually use in VS6.0.

Thanks,'
JT
0
 
LVL 86

Accepted Solution

by:
jkr earned 800 total points
ID: 33746095
Well, that is the managed equivalent to 'main()' - if you don't want this, be sure to create an unmanaged project.
0
 

Author Closing Comment

by:jtran007
ID: 33779999
Thanks,
JT
0

Featured Post

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Article by: SunnyDark
This article's goal is to present you with an easy to use XML wrapper for C++ and also present some interesting techniques that you might use with MS C++. The reason I built this class is to ease the pain of using XML files with C++, since there is…
C++ Properties One feature missing from standard C++ that you will find in many other Object Oriented Programming languages is something called a Property (http://www.experts-exchange.com/Programming/Languages/CPP/A_3912-Object-Properties-in-C.ht…
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
Suggested Courses

649 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question