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

Compiling with g++ - Error - Help

Hi,

I am trying to figure out why this code doesn't work when I compile it
under linux with g++

Following is the code, and the error message I get is:

main.cpp: In function âint main()â:
main.cpp:5: error: conversion from âPerson*â to non-scalar type
âPersonâ requested

I used the following command to compile: g++ Person.h Person.cpp
main.cpp

------------------------------------
//filename: Person.h
class Person
{
private:
int age;
public:
void setAge(int age);
};

--------------------------------------
//filename: Person.cpp
#include "Person.h"

void Person::setAge(int age)
{
this->age = age;
}

--------------------------------------
//filename: main.cpp
#include "Person.h"

int main()
{
Person mark = new Person();
mark.setAge(5);

return 0;
}

----------------------------------------

I am not sure what the error means, but everything looks okay to me.
Looking forward to someone helping me out on this.

Thank you!

Ali

Feb 24 '07 #1
6 1421
al*************@gmail.com wrote:
>
I am trying to figure out why this code doesn't work when I compile it
under linux with g++
Because C++ isn't Java.
Person mark = new Person();
Person *mark = new Person();

--

-- Pete
Roundhouse Consulting, Ltd. (www.versatilecoding.com)
Author of "The Standard C++ Library Extensions: a Tutorial and
Reference." (www.petebecker.com/tr1book)
Feb 24 '07 #2
Hi


<al*************@gmail.comwrote in message
news:11**********************@z35g2000cwz.googlegr oups.com...
Hi,

I am trying to figure out why this code doesn't work when I compile it
under linux with g++

Following is the code, and the error message I get is:

main.cpp: In function âint main()â:
main.cpp:5: error: conversion from âPerson*â to non-scalar type
âPersonâ requested

I used the following command to compile: g++ Person.h Person.cpp
main.cpp

------------------------------------
//filename: Person.h
#include <memory>// <++++++++++++++++
class Person
{
private:
int age;
public:
void setAge(int age);
};

--------------------------------------
//filename: Person.cpp
#include "Person.h"

void Person::setAge(int age)
{
this->age = age;
}

--------------------------------------
//filename: main.cpp
#include "Person.h"

int main()
{
auto_ptr<Personmark = new Person(); // <++++++++++++++++
mark->setAge(5);// <++++++++++++++++
return 0;
}

----------------------------------------

I am not sure what the error means, but everything looks okay to me.
Looking forward to someone helping me out on this.

Thank you!

Ali
See the changes.

Regards, Ron AF Greve

http://www.InformationSuperHighway.eu


Feb 24 '07 #3
Sorry,

Don't forget to throw in a

using namespace std;

In the source file :-)


Regards, Ron AF Greve

http://www.InformationSuperHighway.eu

"Ron AF Greve" <news moonlit xs4all nlwrote in message
news:45*********************@news.xs4all.nl...
Hi


<al*************@gmail.comwrote in message
news:11**********************@z35g2000cwz.googlegr oups.com...
Hi,

I am trying to figure out why this code doesn't work when I compile it
under linux with g++

Following is the code, and the error message I get is:

main.cpp: In function âint main()â:
main.cpp:5: error: conversion from âPerson*â to non-scalar type
âPersonâ requested

I used the following command to compile: g++ Person.h Person.cpp
main.cpp

------------------------------------
//filename: Person.h
#include <memory>// <++++++++++++++++
class Person
{
private:
int age;
public:
void setAge(int age);
};

--------------------------------------
//filename: Person.cpp
#include "Person.h"

void Person::setAge(int age)
{
this->age = age;
}

--------------------------------------
//filename: main.cpp
#include "Person.h"

int main()
{
auto_ptr<Personmark = new Person(); // <++++++++++++++++
mark->setAge(5);// <++++++++++++++++
return 0;
}

----------------------------------------

I am not sure what the error means, but everything looks okay to me.
Looking forward to someone helping me out on this.

Thank you!

Ali
See the changes.

Regards, Ron AF Greve

http://www.InformationSuperHighway.eu


Feb 24 '07 #4
On 25 Feb., 00:33, aliasger.jaf...@gmail.com wrote:
Hi,

I am trying to figure out why this code doesn't work when I compile it
under linux with g++
It has nothing to do with linux og g++
>
Following is the code, and the error message I get is:

main.cpp: In function "int main()":
main.cpp:5: error: conversion from "Person*" to non-scalar type
"Person" requested
[snip]
{
Person mark = new Person();
mark.setAge(5);
[snip]
I am not sure what the error means, but everything looks okay to me.
I find the errormessage quite good. You are using a Person* where you
should have used a Person. A pointer does not support operator dot -
and that should be basic knowledge.
Why do you use operator new? Corrected program is

Person mark;
mark.setAge(5);

/Peter

Feb 24 '07 #5
ali
On Feb 24, 5:44 pm, "Ron AF Greve" <news moonlit xs4all nlwrote:
Hi

<aliasger.jaf...@gmail.comwrote in message

news:11**********************@z35g2000cwz.googlegr oups.com...
Hi,

I am trying to figure out why this code doesn't work when I compile it
under linux with g++

Following is the code, and the error message I get is:

main.cpp: In function âint main()â:
main.cpp:5: error: conversion from âPerson*â to non-scalar type
âPersonâ requested

I used the following command to compile: g++ Person.h Person.cpp
main.cpp

------------------------------------
//filename: Person.h
#include <memory>// <++++++++++++++++

class Person
{
private:
int age;
public:
void setAge(int age);

};

--------------------------------------
//filename: Person.cpp
#include "Person.h"

void Person::setAge(int age)
{
this->age = age;

}

--------------------------------------
//filename: main.cpp
#include "Person.h"

int main()
{
auto_ptr<Personmark = new Person(); // <++++++++++++++++
mark->setAge(5);// <++++++++++++++++

return 0;

}

----------------------------------------
Oh, I get it. Thanks a bunch!!...
>
I am not sure what the error means, but everything looks okay to me.
Looking forward to someone helping me out on this.

Thank you!

Ali

See the changes.

Regards, Ron AF Greve

http://www.InformationSuperHighway.eu

Feb 25 '07 #6
al*************@gmail.com wrote:
....
>
int main()
{
Person mark = new Person();
// try this :-
Person mark;
mark.setAge(5);

return 0;
}
There is no need to call new - you must subsequently call delete if you
do use new.
Feb 25 '07 #7

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

Similar topics

5
by: Mike S. | last post by:
Hello, Has anyone had success compiling the informixdb-1.3 module under python 2.2? It seems the absense of makefile.pre.in in python 2.2 causes the break under py2.2. Is there an easy way...
0
by: Martin Bless | last post by:
I need to access a MSSQL database (MS-Sql, not MySQL!)and would very much like to use mssql-0.09.tar.gz which is available from http://www.object-craft.com.au/projects/mssql/download.html ...
0
by: pruebauno | last post by:
Hello all, I am having issues compiling Python with large file support. I tried forcing the configure script to add it but then it bombs in the make process. Any help will be appreciated. ...
11
by: Arturo DiDonna | last post by:
Hello everyone. I am trying to compile someone else code and I am stuck with compilation problems using the g++ 3.3 compiler. Basically, when compiling the following code, I get this error...
4
by: Aaron Queenan | last post by:
When I build a C++ library to .NET using the managed C++ compiler, I get the following error message: Linking... LINK : error LNK2020: unresolved token (0A000005) _CrtDbgReport LINK : error...
2
by: Erik | last post by:
Hi Everyone, I'm having real problems compiling some source for eVC4++. The errors I am getting are below: It all seems to be centred around winsock. If I move the afsock.h reference to before...
1
by: Mike Hutton | last post by:
I need some help. I am trying to set up our development environment so as to make life easy for my fellow developers (none of whom have used ASP.NET or VS.NET before). We are developing our...
7
by: Sverker Nilsson | last post by:
I have been informed that Guppy-PE (http://guppy-pe.sourceforge.net) has failed to compile its extension modules with a Microsoft .NET 2003 compiler under Windows 2000. One of the problems,...
2
by: renagade629 | last post by:
Can anybody help me understand what i'm doing wrong or what I'm missing? Is there anyother good and commendable C++ program I can use (free) from the internet like Dev C++? I'm having trouble doing...
0
by: =?Utf-8?B?amVmZmVyeQ==?= | last post by:
i need help compiling code dynamically it may involve some reflection so if any one is any good in that field or compiling code this would be a great time to show me what you know. by the way my...
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: 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: 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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.