Hi,
"call()" calles "show()". I got some error as indicated below in the
comments. I tried to delete the definition and declaration of "call()"
and call "show()" in the main() body, then it got compiled. I'm not
sure what's wrong with the following code. Would you please help me to
fix it?
Best wishes,
Peng
#include <iostream>
#include <complex>
template <typename Tp>
class A{
public:
A(){};
void call();
void show();
};
template <>
void A<int>::call(){
A<int>::show();
}
template <>
void A<double>::call(){
A<double>::show();
}
template <>
void A<double>::show(){//get compile error here
std::cout << "double" << std::endl;
}
template <>
void A<int>::show(){
std::cout << "int" << std::endl;
}
int main(int argc, char *argv[]) {
A<double> a;
A<int> b;
a.call();//a.show();
b.call();//b.show();
} 4 1320 Pe*******@gmail.com wrote: "call()" calles "show()". I got some error as indicated below in the comments. I tried to delete the definition and declaration of "call()" and call "show()" in the main() body, then it got compiled. I'm not sure what's wrong with the following code. Would you please help me to fix it?
Best wishes, Peng
#include <iostream> #include <complex>
template <typename Tp> class A{ public: A(){}; void call(); void show(); };
template <> void A<int>::call(){ A<int>::show(); }
template <> void A<double>::call(){ A<double>::show(); }
template <> void A<double>::show(){//get compile error here
WHAT compile error?
The Comeau compiler essentially suggest that both 'show' specialisations
should be moved right after the class template definition. Do it, see
if it fixes your "compile error".
std::cout << "double" << std::endl; }
template <> void A<int>::show(){ std::cout << "int" << std::endl; }
int main(int argc, char *argv[]) { A<double> a; A<int> b; a.call();//a.show(); b.call();//b.show(); }
V
I'm using g++3.3.
Following your suggestion, I got it compiler. But why the order of the
function definitions matters?
Thanks,
Peng Pe*******@gmail.com wrote: I'm using g++3.3.
I don't think it makes any difference.
Following your suggestion, I got it compiler. But why the order of the function definitions matters?
The definitions in this case are also declarations. The calls to those
functions in the 'call' member specialisations probably requires that
the specialisation is declared if it's to be used. I am too lazy to
look in the Standard.
V
In article <11**********************@o13g2000cwo.googlegroups .com>, Pe*******@gmail.com <Pe*******@gmail.com> wrote: Following your suggestion, I got it compiler. But why the order of the function definitions matters?
For the same reason it matters here:
int main()
{
return foo();
}
int foo() { return 0; }
--
Greg Comeau / Comeau for the Mac? Stay tuned.
Comeau C/C++ ONLINE ==> http://www.comeaucomputing.com/tryitout
World Class Compilers: Breathtaking C++, Amazing C99, Fabulous C90.
Comeau C/C++ with Dinkumware's Libraries... Have you tried it? This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: svilen |
last post by:
hello again.
i'm now into using python instead of another language(s) for
describing structures of data, including names, structure,
type-checks, conversions, value-validations, metadata etc....
|
by: Ray Tayek |
last post by:
hi, trying to convert some csv files into xsml and pulling a few hairs
out :(. using the files below. a java program will parse the csv and
take care of strange names and notes that line breaks in...
|
by: Saulius |
last post by:
template<template<typename T> class StoragePolicy>
class construction_info {
// Empty by default, specialize for other types.
};
template<template<typename> class StoragePolicy,
typename...
|
by: PengYu.UT |
last post by:
Hi,
I run into error with the following program. Would you please help me?
Best wishes,
Peng
struct tag1{};
struct tag2{};
|
by: Michael B. |
last post by:
I was just thinking about this, specifically wondering if there's any
features that the C specification currently lacks, and which may be
included in some future standardization.
Of course, I...
|
by: ftjonsson |
last post by:
hello,
I was wondering if anyone could tips me on what I am doing wrong when
writing the following code:
#include <iostream>
using namespace std;
int main ()
{
|
by: RichardOnRails |
last post by:
I have a Stack class that works fine. In particular, when it
encounters an error, it cout's a msg and exits. However, I'd like to
change it to report the error and continue with dummy data as...
|
by: nick4ng |
last post by:
If I have a templated constructor, there is a way to know, at compile
time, the instance when compiling the destructor?
To be clearer my problem is that I have a templated constructor that
is...
|
by: joelkeepup |
last post by:
Hi, I made a change this morning
and now im getting an error that says either "a is undefined or null"
or "e is undefined or null"
the microsoft ajax line is below, I have no idea how to...
|
by: taylorcarr |
last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: aa123db |
last post by:
Variable and constants
Use var or let for variables and const fror constants.
Var foo ='bar';
Let foo ='bar';const baz ='bar';
Functions
function $name$ ($parameters$) {
}
...
|
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...
|
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: 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...
|
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: 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...
| |