473,322 Members | 1,566 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,322 software developers and data experts.

Problem with inner classes and Templates

Hi, when I'm trying to compile this code with gcc 4 I get this strange
error :

alex@deimos:~/Desktop/Image$ make -k Image
g++ Image.cpp -o Image
Image.cpp:29: error: expected initializer before 'Image'
make: *** [Image] Error 1
The code of the source of Image.cpp is the following:

#include <string>
#include <map>

class A {
private:
typedef std::map<std::string, intmaptype_t;

static const maptype_t _mapconst;
static maptype_t _init_mapconst();

}

inline A::maptype_t
A::_init_mapconst() // line 15
{
maptype_t m;
m["aaa"] = 23;
m["acb"] = 42;
return m;

}

const A::maptype_t
A::_mapconst =
A::_init_mapconst();

int main()
{

}

The problem seems to be not present if I remove the template leaving
as a common class the Image one. I think it's due by the fact that
compiler cannot predict the form of Handler before it has not been
istantiated ... but I'm not sure ... could you help me ?

Is a solution to templatizate also the Handler class and moreover move
it outside the Image class ?

Thank you in advance.

Alessandro

Feb 17 '07 #1
2 1664
* al******@gmail.com:
Hi, when I'm trying to compile this code with gcc 4 I get this strange
error :

alex@deimos:~/Desktop/Image$ make -k Image
g++ Image.cpp -o Image
Image.cpp:29: error: expected initializer before 'Image'
make: *** [Image] Error 1
The code of the source of Image.cpp is the following:

#include <string>
#include <map>

class A {
private:
typedef std::map<std::string, intmaptype_t;

static const maptype_t _mapconst;
static maptype_t _init_mapconst();

}

inline A::maptype_t
A::_init_mapconst() // line 15
{
maptype_t m;
m["aaa"] = 23;
m["acb"] = 42;
return m;

}

const A::maptype_t
A::_mapconst =
A::_init_mapconst();

int main()
{

}

1. The error message refers to a line 29, you have singled out line 15.

2. The error message refers to an identifier 'Image', there's no such
identifier in the presented code.

The problem seems to be not present if I remove the template leaving
as a common class the Image one.
3. There's no template definition in the presented code.

I think it's due by the fact that
compiler cannot predict the form of Handler before it has not been
istantiated ... but I'm not sure ... could you help me ?
4. There's no identifier 'Handler' in the presented code.

Is a solution to templatizate also the Handler class and moreover move
it outside the Image class ?
5. Post the code.

--
A: Because it messes up the order in which people normally read text.
Q: Why is it such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?
Feb 17 '07 #2
On 17 Feb, 01:38, "Alf P. Steinbach" <a...@start.nowrote:
* alexr...@gmail.com:
Hi, when I'm trying to compile this code with gcc 4 I get this strange
error :
alex@deimos:~/Desktop/Image$ make -k Image
g++ Image.cpp -o Image
Image.cpp:29: error: expected initializer before 'Image'
make: *** [Image] Error 1
The code of the source of Image.cpp is the following:
#include <string>
#include <map>
class A {
private:
typedef std::map<std::string, intmaptype_t;
static const maptype_t _mapconst;
static maptype_t _init_mapconst();
}
inline A::maptype_t
A::_init_mapconst() // line 15
{
maptype_t m;
m["aaa"] = 23;
m["acb"] = 42;
return m;
}
const A::maptype_t
A::_mapconst =
A::_init_mapconst();
int main()
{
}

1. The error message refers to a line 29, you have singled out line 15.

2. The error message refers to an identifier 'Image', there's no such
identifier in the presented code.
The problem seems to be not present if I remove the template leaving
as a common class the Image one.

3. There's no template definition in the presented code.
I think it's due by the fact that
compiler cannot predict the form of Handler before it has not been
istantiated ... but I'm not sure ... could you help me ?

4. There's no identifier 'Handler' in the presented code.
Is a solution to templatizate also the Handler class and moreover move
it outside the Image class ?

5. Post the code.

--
A: Because it messes up the order in which people normally read text.
Q: Why is it such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?
Sorry I posted the wrong code ... now you can see the correct one ...

TY

Feb 17 '07 #3

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

Similar topics

5
by: devu | last post by:
Currently I'm working on a class that performs a batch process as per scheduling for all employees in a company. Being a batch process load is obviously a huge factor. The process first needs to...
1
by: Oplec | last post by:
Hi, I'm learning C++ as a hobby using The C++ Programming Language : Special Edition by Bjarne Stroustrup. I'm working on chpater 13 exercises that deal with templates. Exercise 13.9 asks for me...
4
by: Leslaw Bieniasz | last post by:
Cracow, 20.09.2004 Hello, I need to implement a library containing a hierarchy of classes together with some binary operations on objects. To fix attention, let me assume that it is a...
13
by: Winbatch | last post by:
Hi, If this should be directed to another group, please let me know... I've been working with templates for a few weeks and have been able to develop some nice code on solaris using the Forte C++...
9
by: MariusI | last post by:
Consider the following class layout public class Order { public ProductOrder AddProductOrder(/* variables required to create a product order */) { /* Check if the product order can be added...
1
by: yoknows | last post by:
Hello .Net Gurus. This is my first post here so I apologize in advance if I have not provided the right information. I hope someone has seen this problem before and can tell me what I am doing...
6
by: Philip Potter | last post by:
I have a graph data structure. It goes something like this: class GraphNode { private: friend class Graph; // successor GraphNodes stored as indices of the Graph's array int value; int next1,...
6
by: alexroat | last post by:
Hi, when I'm trying to compile this code with gcc 4 I get this strange error : alex@deimos:~/Desktop/Image$ make -k Image g++ Image.cpp -o Image Image.cpp:29: error: expected initializer...
3
by: Christof Warlich | last post by:
Hi, I need to specialize an inner template class, but gcc refuses to compile. Here is a minimal example exposing the issue: template<int astruct Outer { template<int bstruct Inner { }; };...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...

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.