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<double>, B1<double>(x,x));//error
} 4 1526 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<double>, 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<double>(), B1<double>(x,x));
or this:
D<double> D_inst = D<double>(A1<double>(), 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<double>(), 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<double>, 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<double>(), B1<double>(x,x));
Using "g++ (GCC) 3.3.4 (pre 3.3.5 20040809)"
the above line produces this error:
"main.cpp:47: error: syntax error before `,' token"
Why? or this: D<double> D_inst = D<double>(A1<double>(), 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<double>, 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<double>(), B1<double>(x,x));
Using "g++ (GCC) 3.3.4 (pre 3.3.5 20040809)" the above line produces this error:
"main.cpp:47: 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<double>()), 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...
|
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...
|
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...
|
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...
|
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>...
|
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...
|
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...
|
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...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
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...
|
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
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
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,...
|
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: 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,...
| |