473,386 Members | 1,606 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Some errors when using empty template argument

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();
}

Jul 23 '05 #1
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
Jul 23 '05 #2
I'm using g++3.3.

Following your suggestion, I got it compiler. But why the order of the
function definitions matters?

Thanks,
Peng

Jul 23 '05 #3
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
Jul 23 '05 #4
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?
Jul 23 '05 #5

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

Similar topics

7
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....
0
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...
7
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...
6
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{};
193
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...
8
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 () {
8
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...
3
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...
2
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...
0
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,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
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$) { } ...
0
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...
0
BarryA
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
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...
0
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...
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...

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.