473,593 Members | 2,818 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

What's wrong with this program?

Could you tell me what's wrong with this program, it doesn't compile:

#include <iostream>
#include <cstdlib>
using namespace std;

class Everything
{
public:
static Everything* Instance()
{
if(instance==0)
instance=new Everything;
return instance;
}
const long double pi;
const long double e;
const long double phi;
private:
Everything():pi (3.14591),e(2.7 1828),phi(1.618 034){}
Everything(cons t Everything&);
Everything& operator=(const Everything&);
private:
static Everything* instance;
};
Everything* Everything::ins tance = 0;// initialize pointer

Everything* var=Instance();
int main()
{
long double* area(const long double& radius, const Everything* var);
long double rad;
cout << "Enter a radius: ";
cin >> rad;
long double* ret=area(rad,va r);
cout << "Area: " << *ret << endl;
delete ret;
system("PAUSE") ;
return EXIT_SUCCESS;
}
long double* area(const long double& radius, const Everything* var)
{
template<class T>T Exp(const T& base,long long exp);
long double* ret=new long double(var->pi*Exp<long double>(radius, 2));
return ret;
}
template<class T>
T Exp(const T& base,long long exp)
{
for(T i=1;exp>0;exp--)
i*=base;
return i;
}

Any suggestions? Thanks!!!

Nov 22 '05 #1
10 3213
"Protoman" <Pr**********@g mail.com> wrote in message
news:11******** *************@g 49g2000cwa.goog legroups.com...
Could you tell me what's wrong with this program, it doesn't compile:


First I'll tell you what's wrong with your post. You posted
code, and only say 'it doesn't compile'. I think you've been
posting (and hopefully reading) here long enough to know that
that is not sufficient.

That said, I don't need to tell you what's wrong with the code,
my compiler (and yours) can. Mine says:

Compiling...
cpp.cpp
cpp.cpp(478) : error C2065: 'Instance' : undeclared identifier
cpp.cpp(478) : error C2440: 'initializing' : cannot convert from 'int' to
'class Everything *'
Conversion from integral type to pointer type requires
reinterpret_cas t, C-style cast or function-style cast
cpp.cpp(493) : error C2951: template declarations are only permitted at
global or namespace scope
cpp.cpp(493) : error C2143: syntax error : missing ';' before 'newline'
cpp.cpp(493) : error C2632: 'long' followed by 'long' is illegal
cpp.cpp(494) : error C2065: 'Exp' : undeclared identifier
cpp.cpp(494) : error C2062: type 'long double' unexpected
cpp.cpp(496) : error C2143: syntax error : missing ';' before '}'
cpp.cpp(496) : error C2143: syntax error : missing ';' before '}'
cpp.cpp(496) : error C2143: syntax error : missing ';' before '}'
cpp.cpp(496) : error C2143: syntax error : missing ';' before '}'
cpp.cpp(496) : error C2143: syntax error : missing ';' before '}'
cpp.cpp(496) : error C2143: syntax error : missing ';' before '}'
cpp.cpp(496) : error C2143: syntax error : missing ';' before '}'
cpp.cpp(496) : error C2143: syntax error : missing ';' before '}'
cpp.cpp(496) : error C2143: syntax error : missing ';' before '}'
cpp.cpp(496) : error C2143: syntax error : missing ';' before '}'
cpp.cpp(496) : error C2143: syntax error : missing ';' before '}'
cpp.cpp(496) : error C2143: syntax error : missing ';' before '}'
cpp.cpp(496) : error C2143: syntax error : missing ';' before '}'
cpp.cpp(496) : error C2143: syntax error : missing ';' before '}'
cpp.cpp(496) : error C2143: syntax error : missing ';' before '}'
cpp.cpp(496) : error C2143: syntax error : missing ';' before '}'
cpp.cpp(496) : error C2143: syntax error : missing ';' before '}'
cpp.cpp(496) : error C2143: syntax error : missing ';' before '}'
cpp.cpp(496) : error C2143: syntax error : missing ';' before '}'
cpp.cpp(496) : error C2143: syntax error : missing ';' before '}'
cpp.cpp(496) : error C2143: syntax error : missing ';' before '}'
cpp.cpp(496) : error C2143: syntax error : missing ';' before '}'
cpp.cpp(496) : error C2143: syntax error : missing ';' before '}'
cpp.cpp(496) : error C2143: syntax error : missing ';' before '}'
cpp.cpp(496) : error C2143: syntax error : missing ';' before '}'
cpp.cpp(496) : error C2143: syntax error : missing ';' before '}'
cpp.cpp(496) : error C2143: syntax error : missing ';' before '}'
cpp.cpp(496) : error C2143: syntax error : missing ';' before '}'
cpp.cpp(496) : error C2143: syntax error : missing ';' before '}'
cpp.cpp(496) : error C2143: syntax error : missing ';' before '}'
cpp.cpp(496) : error C2143: syntax error : missing ';' before '}'
cpp.cpp(496) : error C2143: syntax error : missing ';' before '}'
cpp.cpp(496) : error C2143: syntax error : missing ';' before '}'
cpp.cpp(496) : error C2143: syntax error : missing ';' before '}'
cpp.cpp(496) : error C2143: syntax error : missing ';' before '}'
cpp.cpp(496) : error C2143: syntax error : missing ';' before '}'
cpp.cpp(496) : error C2143: syntax error : missing ';' before '}'
cpp.cpp(496) : error C2143: syntax error : missing ';' before '}'
cpp.cpp(496) : error C2143: syntax error : missing ';' before '}'
cpp.cpp(496) : error C2143: syntax error : missing ';' before '}'
cpp.cpp(496) : error C2143: syntax error : missing ';' before '}'
cpp.cpp(496) : error C2143: syntax error : missing ';' before '}'
cpp.cpp(496) : error C2143: syntax error : missing ';' before '}'
cpp.cpp(496) : error C2143: syntax error : missing ';' before '}'
cpp.cpp(496) : error C2143: syntax error : missing ';' before '}'
cpp.cpp(496) : error C2143: syntax error : missing ';' before '}'
cpp.cpp(496) : error C2143: syntax error : missing ';' before '}'
cpp.cpp(496) : error C2143: syntax error : missing ';' before '}'
cpp.cpp(496) : error C2143: syntax error : missing ';' before '}'
cpp.cpp(496) : error C2143: syntax error : missing ';' before '}'
cpp.cpp(496) : error C2143: syntax error : missing ';' before '}'
cpp.cpp(496) : error C2143: syntax error : missing ';' before '}'
cpp.cpp(496) : error C2143: syntax error : missing ';' before '}'
cpp.cpp(496) : error C2143: syntax error : missing ';' before '}'
cpp.cpp(496) : error C2143: syntax error : missing ';' before '}'
cpp.cpp(496) : error C2143: syntax error : missing ';' before '}'
cpp.cpp(496) : error C2143: syntax error : missing ';' before '}'
cpp.cpp(496) : error C2143: syntax error : missing ';' before '}'
cpp.cpp(496) : error C2143: syntax error : missing ';' before '}'
cpp.cpp(496) : error C2143: syntax error : missing ';' before '}'
cpp.cpp(496) : error C2143: syntax error : missing ';' before '}'
cpp.cpp(496) : error C2143: syntax error : missing ';' before '}'
cpp.cpp(496) : error C2143: syntax error : missing ';' before '}'
cpp.cpp(496) : error C2143: syntax error : missing ';' before '}'
cpp.cpp(496) : error C2143: syntax error : missing ';' before '}'
cpp.cpp(496) : error C2143: syntax error : missing ';' before '}'
cpp.cpp(496) : error C2143: syntax error : missing ';' before '}'
cpp.cpp(496) : error C2143: syntax error : missing ';' before '}'
cpp.cpp(496) : error C2143: syntax error : missing ';' before '}'
cpp.cpp(496) : error C2143: syntax error : missing ';' before '}'
cpp.cpp(496) : error C2143: syntax error : missing ';' before '}'
cpp.cpp(496) : error C2143: syntax error : missing ';' before '}'
cpp.cpp(496) : error C2143: syntax error : missing ';' before '}'
cpp.cpp(496) : error C2143: syntax error : missing ';' before '}'
cpp.cpp(496) : error C2143: syntax error : missing ';' before '}'
cpp.cpp(496) : error C2143: syntax error : missing ';' before '}'
cpp.cpp(496) : error C2143: syntax error : missing ';' before '}'
cpp.cpp(496) : error C2143: syntax error : missing ';' before '}'
cpp.cpp(496) : error C2143: syntax error : missing ';' before '}'
cpp.cpp(496) : error C2143: syntax error : missing ';' before '}'
cpp.cpp(496) : error C2143: syntax error : missing ';' before '}'
cpp.cpp(496) : error C2143: syntax error : missing ';' before '}'
cpp.cpp(496) : error C2143: syntax error : missing ';' before '}'
cpp.cpp(496) : error C2143: syntax error : missing ';' before '}'
cpp.cpp(496) : error C2143: syntax error : missing ';' before '}'
cpp.cpp(496) : error C2143: syntax error : missing ';' before '}'
cpp.cpp(496) : error C2143: syntax error : missing ';' before '}'
cpp.cpp(496) : error C2143: syntax error : missing ';' before '}'
cpp.cpp(496) : error C2143: syntax error : missing ';' before '}'
cpp.cpp(496) : error C2143: syntax error : missing ';' before '}'
cpp.cpp(496) : error C2143: syntax error : missing ';' before '}'
cpp.cpp(496) : error C2143: syntax error : missing ';' before '}'
cpp.cpp(496) : error C2143: syntax error : missing ';' before '}'
cpp.cpp(496) : error C2143: syntax error : missing ';' before '}'
cpp.cpp(496) : fatal error C1003: error count exceeds 100; stopping
compilation
Error executing cl.exe.

cpp.obj - 102 error(s), 0 warning(s)

What to do:

while(errors)
{
fix_first_error ();
recompile();
}
-Mike
Nov 22 '05 #2
OK, I fixed some of the errors, but it still won't work. And how is
instance undeclared?

Code:

template<class T>
T Exp(const T& base,long long exp)
{
T i;
for(i=1;exp>0;e xp--)
i*=base;
return i;
}

long double* area(const long double& radius, const Everything* var)
{
long double* ret=new long double(var->pi*Exp<long double>(radius, 2));
return ret;
}

class Everything
{
public:
static Everything* Instance()
{
if(instance==0)
instance=new Everything;
return instance;
}
const long double pi;
const long double e;
const long double phi;
private:
Everything():pi (3.14591),e(2.7 1828),phi(1.618 034){}
Everything(cons t Everything&);
Everything& operator=(const Everything&);
private:
static Everything* instance;
};
Everything* Everything::ins tance = 0;// initialize pointer

Everything* var=Instance();
int main()
{
cout << "Enter a radius: ";
cin >> rad;
long double* ret=area(rad,va r);
cout << "Area: " << *ret << endl;
delete ret;
system("PAUSE") ;
return EXIT_SUCCESS;
}

Could you tell me *exactly* hat's wrong, b/c my debugger is broken?
Thanks!!!

Nov 22 '05 #3

"Protoman" <Pr**********@g mail.com> wrote in message
news:11******** **************@ z14g2000cwz.goo glegroups.com.. .
OK, I fixed some of the errors, but it still won't work. And how is
instance undeclared?


Instance() is a function declared inside your class.
Everything* var=Instance(); is trying to use a global Instance() which
doesn't exist.
That is how it's undeclared.
Nov 22 '05 #4

Jim Langston wrote:
"Protoman" <Pr**********@g mail.com> wrote in message
news:11******** **************@ z14g2000cwz.goo glegroups.com.. .
OK, I fixed some of the errors, but it still won't work. And how is
instance undeclared?


Instance() is a function declared inside your class.
Everything* var=Instance(); is trying to use a global Instance() which
doesn't exist.
That is how it's undeclared.


How? It's static!!!!

Nov 22 '05 #5
Never mind, I fixed that, now its saying that var is undeclared in the
area function and that's there's a missing semicolon and stuff.
Here's the code:

#include <iostream>
#include <cstdlib>
using namespace std;

template<class T>
T Exp(const T& base,long long exp)
{
T i;
for(i=1;exp>0;e xp--)
i*=base;
return i;
}

long double* area(const long double& radius, const Everything* var)
{
long double* ret=new long double((var->pi)*Exp<long double>(radius, 2));
return ret;
}

class Everything
{
public:
static Everything* Instance()
{
if(instance==0)
instance=new Everything;
return instance;
}
const long double pi;
const long double e;
const long double phi;
private:
Everything():pi (3.14591),e(2.7 1828),phi(1.618 034){}
Everything(cons t Everything&);
Everything& operator=(const Everything&);
private:
static Everything* instance;
};
Everything* Everything::ins tance = 0;// initialize pointer

Everything* var=Everything: :Instance();
int main()
{
cout << "Enter a radius: ";
long double rad;
cin >> rad;
long double* ret=area(rad,va r);
cout << "Area: " << *ret << endl;
delete ret;
system("PAUSE") ;
return EXIT_SUCCESS;
}

Any suggestions? Thanks!!!

Nov 22 '05 #6

"Protoman" <Pr**********@g mail.com> wrote in message
news:11******** **************@ z14g2000cwz.goo glegroups.com.. .
Never mind, I fixed that, now its saying that var is undeclared in the
area function and that's there's a missing semicolon and stuff.
Here's the code:

#include <iostream>
#include <cstdlib>
using namespace std;

template<class T>
T Exp(const T& base,long long exp)
{
T i;
for(i=1;exp>0;e xp--)
i*=base;
return i;
}

long double* area(const long double& radius, const Everything* var)
{
long double* ret=new long double((var->pi)*Exp<long double>(radius, 2));
return ret;
}

class Everything
{
public:
static Everything* Instance()
{
if(instance==0)
instance=new Everything;
return instance;
}
const long double pi;
const long double e;
const long double phi;
private:
Everything():pi (3.14591),e(2.7 1828),phi(1.618 034){}
Everything(cons t Everything&);
Everything& operator=(const Everything&);
private:
static Everything* instance;
};
Everything* Everything::ins tance = 0;// initialize pointer

Everything* var=Everything: :Instance();
int main()
{
cout << "Enter a radius: ";
long double rad;
cin >> rad;
long double* ret=area(rad,va r); I see var here, where is it declared?
cout << "Area: " << *ret << endl;
delete ret;
system("PAUSE") ;
return EXIT_SUCCESS;
}

Any suggestions? Thanks!!!


Yes, read your error messages and fix whey they tell you is broken.
Nov 22 '05 #7
Protoman wrote:
long double* area(const long double& radius, const Everything* var)
{
long double* ret=new long double((var->pi)*Exp<long double>(radius, 2));
return ret;
}

class Everything
{


The function "area" uses "Everything " and derefernces a variable of
that type without telling what "Everything " is. This is precisely what
the compiler complains about. Move the definition of "area" below the
definition of "Everything ".

Nov 22 '05 #8

"Protoman" <Pr**********@g mail.com> wrote in message
news:11******** *************@g 44g2000cwa.goog legroups.com...

Jim Langston wrote:
"Protoman" <Pr**********@g mail.com> wrote in message
news:11******** **************@ z14g2000cwz.goo glegroups.com.. .
> OK, I fixed some of the errors, but it still won't work. And how is
> instance undeclared?


Instance() is a function declared inside your class.
Everything* var=Instance(); is trying to use a global Instance() which
doesn't exist.
That is how it's undeclared.


How? It's static!!!!


That's completely irrelevant. Go back to your textbook
and read about 'scope'.

-Mike
Nov 23 '05 #9

Protoman wrote:
Jim Langston wrote:
"Protoman" <Pr**********@g mail.com> wrote in message
news:11******** **************@ z14g2000cwz.goo glegroups.com.. .
OK, I fixed some of the errors, but it still won't work. And how is
instance undeclared?


Instance() is a function declared inside your class.
Everything* var=Instance(); is trying to use a global Instance() which
doesn't exist.
That is how it's undeclared.


How? It's static!!!!


You need to give it scope:

Everything::Ins tance() is the correct way to call that funct.

Nov 23 '05 #10

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

Similar topics

137
7037
by: Philippe C. Martin | last post by:
I apologize in advance for launching this post but I might get enlightment somehow (PS: I am _very_ agnostic ;-). - 1) I do not consider my intelligence/education above average - 2) I am very pragmatic - 3) I usually move forward when I get the gut feeling I am correct - 4) Most likely because of 1), I usually do not manage to fully explain 3) when it comes true. - 5) I have developed for many years (>18) in many different environments,...
125
14652
by: Sarah Tanembaum | last post by:
Beside its an opensource and supported by community, what's the fundamental differences between PostgreSQL and those high-price commercial database (and some are bloated such as Oracle) from software giant such as Microsoft SQL Server, Oracle, and Sybase? Is PostgreSQL reliable enough to be used for high-end commercial application? Thanks
5
2824
by: titan0111 | last post by:
#include<iostream> #include<iomanip> #include<cstring> #include<fstream> using namespace std; class snowfall { private: int ft;
1
2140
by: Qiangning Hong | last post by:
I decide to seperate my data collection routine from my data analysis and storage program to a seperate process, so I try to use the new subprocess model in Python 2.4. The main program spawns the subprocess and receives data from the pipe. When some event occurs (e.g. the user clicks the 'Stop' button on GUI), the main program will send the subprocess a command to change its behavior or ask it to exit. However, my code (attached...
46
4184
by: Keith K | last post by:
Having developed with VB since 1992, I am now VERY interested in C#. I've written several applications with C# and I do enjoy the language. What C# Needs: There are a few things that I do believe MSFT should do to improve C#, however. I know that in the "Whidbey" release of VS.NET currently
669
25771
by: Xah Lee | last post by:
in March, i posted a essay “What is Expressiveness in a Computer Language”, archived at: http://xahlee.org/perl-python/what_is_expresiveness.html I was informed then that there is a academic paper written on this subject. On the Expressive Power of Programming Languages, by Matthias Felleisen, 1990. http://www.ccs.neu.edu/home/cobbe/pl-seminar-jr/notes/2003-sep-26/expressive-slides.pdf
3
2741
by: belton180 | last post by:
CODE]../* Program function: Simulate the stack using a stack limit of 10. Display a menu for the the following. Create a stack Insert an item in the stack Pop an item from the stack Peep/view the item at the top of the stack Current value of top View all items stored in the stack Quit *the stack accepts lowercase & uppercase characters only from A-Z
20
2802
by: Daniel.C | last post by:
Hello. I just copied this code from my book with no modification : #include <stdio.h> /* count characters in input; 1st version */ main() { long nc; nc = 0;
12
2098
by: broli | last post by:
#include<stdio.h> #include<stdlib.h> struct point { double x, y, z;
4
1957
by: hirsh.dan | last post by:
i have a functions that writes information to a file. inside that function i have a line in which i call another function. if this line is executed, nothing is written to the file, but if i remark that line, it is written. i wanna understand what's wrong and fix it, but can't find what is wrong. also this line is mandatory in my code. the code attached is in the link, minimized to the needed info, a bit different then the way it's...
0
7936
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, well explore What is ONU, What Is Router, ONU & Routers main usage, and What is the difference between ONU and Router. Lets take a closer look ! Part I. Meaning of...
0
7874
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
7997
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8227
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
6646
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development projectplanning, coding, testing, and deploymentwithout human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
5738
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupr who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5402
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
3853
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
1469
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.