Hi,
It seems that the line with "//no error" and "//error" are the same.
However, the second one give an error.
I'm using g++-3.3.
The error message was:
g++-3.3 -g -c -o main.o main.cc
main.cc: In function `int main(int, char**)':
main.cc:85: error: parse error before `,' token
make: *** [main.o] Error 1
Best wishes,
Peng
template <typename __Tp>
class A{
public:
A(){};
~A(){};
virtual void fun() = 0;
};
template <typename __Tp>
class A1 : public A<__Tp>{
public:
A1(){};
~A1(){};
virtual void fun() {};
};
template <typename __Tp>
class B{
public:
B(__Tp x, __Tp y, __Tp z){};
~B(){};
virtual void fun() = 0;
};
template <typename __Tp>
class B1 : public B<__Tp>{
public:
B1(__Tp x, __Tp y): B<__Tp>(x, x, y){};
~B1(){};
virtual void fun() {};
};
template <typename __Tp>
class D{
public:
D(const A<__Tp> &A_inst, const B<__Tp> &B_inst){};
~D(){};
};
int main(int argc, char *argv[])
{
const double x = 0;
A1<double> A1_inst;
B1<double> B1_inst(x, x);
//D<double> D_inst(A1_inst, B1_inst);//no error
D<double> D_inst(A1<doubl e>, B1<double>(x,x) );//error
} 4 1541 Pe*******@gmail .com wrote: Hi,
....
int main(int argc, char *argv[]) { const double x = 0; A1<double> A1_inst; B1<double> B1_inst(x, x); //D<double> D_inst(A1_inst, B1_inst);//no error D<double> D_inst(A1<doubl e>, B1<double>(x,x) );//error }
This is being interpreted as a declaration of a function named D_inst.
Try this:
D<double> D_inst(A1<doubl e>(), B1<double>(x,x) );
or this:
D<double> D_inst = D<double>(A1<do uble>(), B1<double>(x,x) ); Pe*******@gmail .com wrote: It seems that the line with "//no error" and "//error" are the same. However, the second one give an error.
I'm using g++-3.3.
cat main.cpp
template <typename __Tp>
class A {
public:
A(void) { };
~A(void) { };
virtual void fun(void) = 0;
};
template <typename __Tp>
class A1: public A<__Tp> {
public:
A1(void) { };
~A1(void) { };
virtual void fun(void) { };
};
template <typename __Tp>
class B {
public:
B(__Tp x, __Tp y, __Tp z) { };
~B(void) { };
virtual void fun(void) = 0;
};
template <typename __Tp>
class B1: public B<__Tp> {
public:
B1(__Tp x, __Tp y): B<__Tp>(x, x, y) { };
~B1(void) { };
virtual void fun(void) {};
};
template <typename __Tp>
class D {
public:
D(const A<__Tp> &A_inst, const B<__Tp> &B_inst) { };
~D(void) { };
};
int main(int argc, char *argv[]) {
const double x = 0;
A1<double> A1_inst;
B1<double> B1_inst(x, x);
//D<double> D_inst(A1_inst, B1_inst);//no error
D<double> D_inst(A1<doubl e>(), B1<double>(x, x));//error
return 0;
}
g++ -Wall -ansi -pedantic -o main main.cpp
main.cpp: In instantiation of `A<double>':
main.cpp:10: instantiated from `A1<double>'
main.cpp:43: instantiated from here
main.cpp:2: warning: `class A<double>' \
has virtual functions but non-virtual destructor
main.cpp: In instantiation of `A1<double>':
main.cpp:43: instantiated from here
main.cpp:10: warning: `class A1<double>' \
has virtual functions but non-virtual destructor
main.cpp: In instantiation of `B<double>':
main.cpp:26: instantiated from `B1<double>'
main.cpp:44: instantiated from here
main.cpp:18: warning: `class B<double>' \
has virtual functions but non-virtual destructor
main.cpp: In instantiation of `B1<double>':
main.cpp:44: instantiated from here
main.cpp:26: warning: `class B1<double>' \
has virtual functions but non-virtual destructor
g++ --version | head -1
g++ (GCC) 3.4.1
Gianni Mariani wrote: Pe*******@gmail .com wrote: Hi,
...
int main(int argc, char *argv[]) { const double x = 0; A1<double> A1_inst; B1<double> B1_inst(x, x); //D<double> D_inst(A1_inst, B1_inst);//no error D<double> D_inst(A1<doubl e>, B1<double>(x,x) );//error }
This is being interpreted as a declaration of a function named D_inst.
Try this: D<double> D_inst(A1<doubl e>(), B1<double>(x,x) );
Using "g++ (GCC) 3.3.4 (pre 3.3.5 20040809)"
the above line produces this error:
"main.cpp:4 7: error: syntax error before `,' token"
Why? or this: D<double> D_inst = D<double>(A1<do uble>(), B1<double>(x,x) );
This 2nd solution works. It's creating a temp D<double> then
copying it to D_inst. Why should that work, but your first
solution not work? You first solution calls the constructor
for A<double> directly, and looks perfectly legal.
Regards,
Larry
--
Anti-spam address, change each 'X' to '.' to reply directly.
Larry I Smith wrote: Gianni Mariani wrote: Pe*******@gmail .com wrote: Hi,
...
int main(int argc, char *argv[]) { const double x = 0; A1<double> A1_inst; B1<double> B1_inst(x, x); //D<double> D_inst(A1_inst, B1_inst);//no error D<double> D_inst(A1<doubl e>, B1<double>(x,x) );//error }
This is being interpreted as a declaration of a function named D_inst.
Try this: D<double> D_inst(A1<doubl e>(), B1<double>(x,x) );
Using "g++ (GCC) 3.3.4 (pre 3.3.5 20040809)" the above line produces this error:
"main.cpp:4 7: error: syntax error before `,' token"
Why?
Adding the empty parentheses hasn't changed anything; the compiler will
still parse it incorrectly. Try putting parentheses around the
temporary object:
D<double> D_inst((A1<doub le>()), B1<double>(x,x) );
Incidentally, this is an instance of "C++'s Most Vexing Parse" from
Scott Meyers' book _Effective_STL_ .
Kristo This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
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
|
by: Cherrish Vaidiyan |
last post by:
Frinds,
Hope everyone is doing fine.i feel pointers to be the most toughest
part in C. i have just completed learning pointers & arrays related
portions. I need to attend technical interview on C. wat type of
questions should be expected? Which part of C language do the staff
give more concern?
The interviewers have just mentioned that .. i will have interview on
C.
Also can anyone can help me with sites where i can go thru sample
|
by: jacob navia |
last post by:
I would like to add at the beginning of the C tutorial I am writing
a short blurb about what "types" are. I came up with the following text.
Please can you comment?
Did I miss something?
Is there something wrong in there?
--------------------------------------------------------------------
Types
A type is a definition for a sequence of storage bits. It gives the
meaning of the data stored in memory. If we say that the object a is an
|
by: alternativa |
last post by:
Hi,
I have problem with the following function - it was intended to ask a
user for a 4-digits number:
double ask_for_number (void)
{
char *notint;
char s2;
double entered_number;
|
by: ben.carbery |
last post by:
Hi,
I have just written a simple program to get me started in C that
calculates the number of days since your birthdate.
One thing that confuses me about the program (even though it works) is
how global variables and function returns work...
For example, I have a global array "char datestring;" which is
defined in the function speakdate. speakdate just converts a set of
integers (date variables) to a string.
| |
by: noridotjabi |
last post by:
Okay. I'm quite embarased to be asking this but I cannot seem to get
files to work. I don't know what the problem is. Is there something
wrong with this: (file related)
#include <stdio.h>
main() {
FILE *pfsin;
pfsin = fopen("msm.pfs", "r");
char mystr;
|
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
|
by: Ryan |
last post by:
{"POINTID":77902,"MAPID":762,"LONG":-122.21654892,"LAT":"37.1834331019","CITY":"Boulder
Creek","STATE":"CA","DIST":5745.4}
I get an "invalid label" error...
I'm kinda new to this. Thanks!
|
by: Sunil Korah |
last post by:
Hi,
I haven't used access reports much. I have a problem in getting the
total of a group.
I have 3 fields, ProgName (Program name), Pname (Participant's name)
and PCategory (Participant category)
PCategory can have values 'SC', 'ST' and 'Others'
|
by: chutsu |
last post by:
Ok Here is a problem, I got a imaginary database program that I need
to code, to add a patient I have function inser_patient. but when I
try to input the details it doesn't quite work the way I wanted it to.
Code:
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <string.h>
|
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...
| |
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,...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
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...
|
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...
|
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 we have to send another system
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
|
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |