473,473 Members | 1,469 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

syntax error : 'constant'

this is example of what is going on my program, and the error im getting :

when i try to compile the following :

#include <iostream>
using namespace std;

class first {
public:
first(int max) { };
};

class whatever {
public:
whatever() { };
private:
first sowhat(2);
};

I get the error, syntax error : 'constant'
any ideas to solve it?
Jul 22 '05 #1
2 4157
"Someonekicked" <so***********@comcast.net> wrote...
this is example of what is going on my program, and the error im getting :

when i try to compile the following :

#include <iostream>
using namespace std;

class first {
public:
first(int max) { };
Lose the extraneous semicolon.
};

class whatever {
public:
whatever() { };

Lose the extraneous semicolon.
private:
first sowhat(2);
What are you trying to accomplish? Are you trying to define a member
and initialise it here? You can't. Initialisation is done in the
constructor. Now, you wrote a default constructor and it does nothing
in your case. Why do you think you need it, then?
};

I get the error, syntax error : 'constant'
any ideas to solve it?


Yes. How about your book, doesn't it tell you how to initialise members
in the constructor?

class whatever { ...
whatever() : sowhat(2) {}
...
};

Recently there were such basic questions here I am wondering whether
some folks lost the ability to absorb necessary knowledge from books
altogether. Present company excluded, of course...

V
Jul 22 '05 #2

"Someonekicked" <so***********@comcast.net> wrote in message
news:Ge********************@comcast.com...
this is example of what is going on my program, and the error im getting :

when i try to compile the following :

#include <iostream>
using namespace std;

class first {
public:
first(int max) { };
};

class whatever {
public:
whatever() { };
private:
first sowhat(2);
};

I get the error, syntax error : 'constant'
any ideas to solve it?


#include <iostream>

class first
{
public:
first(int max) : m (max) { };
int value() const { return m; }

private:
int m;
};

class whatever
{
public:
whatever(int arg) : sowhat(arg) { };
int f() const { return sowhat.value(); }
private:
first sowhat;
};

int main()
{
whatever w(2);
std::cout << w.f() << '\n'; /* prints 2 */
return 0;
}

-Mike
Jul 22 '05 #3

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

Similar topics

699
by: mike420 | last post by:
I think everyone who used Python will agree that its syntax is the best thing going for it. It is very readable and easy for everyone to learn. But, Python does not a have very good macro...
0
by: Mark Wilson | last post by:
On Saturday, October 4, 2003, at 03:13 PM, Mario S. Mommer wrote: > > jcb@iteris.com (MetalOne) writes: >> I have tried on 3 occassions to become a LISP programmer, based upon >> the constant...
8
by: Christian Brechbühler | last post by:
I get a compile time error that I don't understand. ======================================= begin constructor.cc ====== struct Negate {}; class A { int i; public: A(double x ):...
24
by: deko | last post by:
I'm trying to log error messages and sometimes (no telling when or where) the message contains a string with double quotes. Is there a way get the query to insert the string with the double...
3
by: ollii | last post by:
im creating a iterrative server and i get this error error: syntax error before numeric constant and this errors occurs near this line: int listen(sock,5); need help
3
by: rorni | last post by:
Hi, I'm porting code from Windows to HP-UX 11, compiling with g++. I'm getting a compilation error on the system's debug.h include file, which is included very indirectly through a series of...
1
by: dewi | last post by:
Dear All, I am trying to compile a C code using Visual C++. Can anyone explain how to solve it? Thank You. #include <math.h> #include <string.h> #include "RV2AJFRONT_NEW.h" #include...
7
by: Guillaume Dargaud | last post by:
Hello all, I have an example of working code under my eyes that goes as follow: unsigned long address=0x400000; (void (*)(void)address)(); It's supposed to jump start a kernel loaded at that...
2
by: tvnaidu | last post by:
I am getting this error for line 108, I kept C code also below, any idea?. main.c:108: underscore in number main.c:108: syntax error before numeric constant 104: #define...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
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...
0
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 project—planning, coding, testing,...
0
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...
0
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...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
muto222
php
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.