473,405 Members | 2,187 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,405 software developers and data experts.

problem with structure in function

Hi!
I have a code that looks some thing like this

void function()
{
struct st1
{
template<...>
struct st2
{
static void func2(){...}
}
}
}

I'm using VC++ 2003 and I get the error some thing like:
You can't have template in structure defined in function

Does anyone know if this defined in standard or VC++ 2003 is not fully
supporting standard in this case.

Thx!

P.S. I need that so that objects defined in function would be in global
scope of structure, and structure is actually body of static for loop
Jul 22 '05 #1
4 2459

"Zoran Stipanicev" <no@spam.com> wrote in message
Hi!
Merry Christmas to all readers of comp.lang.c++.
I have a code that looks some thing like this

void function()
{
struct st1
{
template<...>
struct st2
{
static void func2(){...}
}
}
}

I'm using VC++ 2003 and I get the error some thing like:
You can't have template in structure defined in function

Does anyone know if this defined in standard or VC++ 2003 is not fully
supporting standard in this case.


VC++ is correct. 14.5.2/2 reads - " local class shall not have member
templates."

Sharad
Jul 22 '05 #2

Sharad Kala wrote:
"Zoran Stipanicev" <no@spam.com> wrote in message
Hi!
Merry Christmas to all readers of comp.lang.c++.
I have a code that looks some thing like this

void function()
{
struct st1
{
template<...>
struct st2
{
static void func2(){...}
}
}
}

I'm using VC++ 2003 and I get the error some thing like:
You can't have template in structure defined in function

Does anyone know if this defined in standard or VC++ 2003 is not fully supporting standard in this case.


I tried the same code with Microsofts Visual studio 6
it works perfectly fine
I even added a template class and a template function within the
structure but didn't get any errors. I don't understand how at one can
compile to standards at one point and not at other.
VC++ is correct. 14.5.2/2 reads - " local class shall not have member
templates."

Sharad

14.5.2/1 states that a template class can be declared within a class or
template
I modified the function something like this and it compiled sucessfully
void function()
{
struct st1
{
template<class T> sort(T);
struct st2
{
template<class T, int i> class Buffer {
T v[i] ;
int sz;
public:
Buffer() : sz(i) {}
// ...
};
static void func2(){}
};
};

}

Can you please explain how ?

Jul 22 '05 #3

"Sagar Choudhary" <sa*************@gmail.com> wrote in message

Sharad Kala wrote:
"Zoran Stipanicev" <no@spam.com> wrote in message
Hi!
Merry Christmas to all readers of comp.lang.c++.
I have a code that looks some thing like this

void function()
{
struct st1
{
template<...>
struct st2
{
static void func2(){...}
}
}
}

I'm using VC++ 2003 and I get the error some thing like:
You can't have template in structure defined in function

Does anyone know if this defined in standard or VC++ 2003 is not fully supporting standard in this case.
I tried the same code with Microsofts Visual studio 6
it works perfectly fine

Who told you that MS VC 6 is compliant to the Standard in this regard ? In
fact it is quite infamous for its template support. Hang on here for some
time and you will know it.
I even added a template class and a template function within the
structure but didn't get any errors. I don't understand how at one can
compile to standards at one point and not at other.


Compilers have a good property like (most) human beings and that's to learn
from their mistakes. VC++ 7.0 got a little close to the Standard, 7.1 still
closer and 8 is still more closer.

VC++ is correct. 14.5.2/2 reads - " local class shall not have member
templates."

Sharad

14.5.2/1 states that a template class can be declared within a class or
template
I modified the function something like this and it compiled sucessfully
void function()
{
struct st1
{
template<class T> sort(T);
struct st2
{
template<class T, int i> class Buffer {
T v[i] ;
int sz;
public:
Buffer() : sz(i) {}
// ...
};
static void func2(){}
};
};

}

Can you please explain how ?


All I can say is that don't believe your compilers all the time.

Sharad

Jul 22 '05 #4
Sagar Choudhary wrote:

Your code fixed does not compile with GCC 3.3.1 too:

void function()
{
struct st1
{
template<class T>
struct st2
{
static void func2(){}
};
};
}

int main()
{
function();
}
C:\c\temp.cpp In function `void function()':
9 C:\c\temp.cpp invalid declaration of member template `struct
function()::st1::st2<T>' in local class


--
Ioannis Vranos

http://www23.brinkster.com/noicys
Jul 22 '05 #5

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

Similar topics

1
by: drife | last post by:
Hello, Does anyone have an efficient Python routine for calculating the structure function? Thanks very much, Daran
1
by: TheOne | last post by:
I have two classes: class OntologyParser { ... protected: virtual void startElement(void *userData, const char *name, const char **atts); virtual void endElement(void *userData, const char...
2
by: enio | last post by:
Hi, I intend to get some answer from postgres concerning if an update command has altered some records in the database. To do this I coded this function: create or replace function...
0
by: Crystal | last post by:
I have created a small program that prints out an organization chart in PHP using the GD lib's imagecreate, imageline and imagestring functions. Basically, a user selects an employee from a...
6
by: Jay | last post by:
Hi All, If we define a template function within a structure and when calling the function if we specify the typename, MSVC6 throws an error saying that typename was not expected (Error C2062)....
6
by: mforema | last post by:
Hi Everybody, I have a function that worked perfectly when it was used in a query. I received help in creating this function from this discussion: Help with Query and Subform - post #18 ...
8
by: cpptutor2000 | last post by:
Could some C guru please help me? I have a function that takes as an argument a pointer to an array of unsigned chars (basically a hex representation of a dotted decimal IP address). When I print...
4
jenkinsloveschicken
by: jenkinsloveschicken | last post by:
I imagine this is a n00b mistake, but the problem I am having is that the first function(stratQual) is evaluating to "No" despite the argument being passed to it being greater than 80.00. The second...
3
by: viki1967 | last post by:
Hi there. I have a problem with function updateSum(id). The code is this: <script language="javascript" type="text/javascript"> <!--
2
by: presencia | last post by:
Hi everyone, I have written a small program running fine until a Segmentation fault. Using a debugger I have localized the function the fault happens in. The Signal appears during a call to delete...
0
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
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: 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
marktang
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,...
0
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...
0
Oralloy
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,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
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...
0
agi2029
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 project—planning, coding, testing,...

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.