From: SM on
Hi,
I have ATL project in VS2008.
I'm trying to initialize the structure as below in the header
file(test.h)
#pragma once

#include "resource.h" // main symbols

#include <atlhost.h>

typedef struct{
int a;
int b;
}TestStructure;
class CTestStructureDialog :
public CAxDialogImpl<CTestStructureDialog>
{
public:
TestStructure *t2={0,1}
};
I'm getting error as below
error C2059: syntax error : '{'
error C2334: unexpected token(s) preceding '{'; skipping apparent
function body
How to initialize the pointer structure?

When i initialise at .cpp file using t2=new TestStructure, it's
working fine, how i can assign default values in new TestStructure

When I tried without initialize and refer the structure in another
class,
Class name :CTest1(file test1.h)
class CTest1 :
public CAxDialogImpl<CTest1>, public CUpdateUI<CTest1>,
public CMessageFilter, public CIdleHandler
{
public:
TestStructure t3; // getting error in this line error C2146: syntax
error : missing ';' before identifier

};
I'm getting error as
error C2146: syntax error : missing ';' before identifier.
The actual code is converted from VC++6.0 to VS2008 using project
conversion wizard in VS2008.




Thanks,
Sony

From: Ulrich Eckhardt on
SM wrote:
> typedef struct{
> int a;
> int b;
> }TestStructure;

struct TestStructure { ... };

Drop the 'typedef' to assign a typename to an anonymous structure.

> class CTestStructureDialog :
> public CAxDialogImpl<CTestStructureDialog>
> {
> public:
> TestStructure *t2={0,1}
> };
> I'm getting error as below
> error C2059: syntax error : '{'
> error C2334: unexpected token(s) preceding '{'; skipping apparent
> function body
> How to initialize the pointer structure?

Two things:
1. You can only initialise a pointer to a pointer value, while you are
giving two integers here to (probably) initialise what the pointer points
to. You probably don't want a pointer. As a general rule, don't use
pointers.
2. Initialise things in the constructor's "initialiser list", which should
be explained in every C++ book. Note though that you can't initialise an
aggregate like TestStructure unless it has a constructor itself.

> public CAxDialogImpl<CTest1>, public CUpdateUI<CTest1>,
^^^^^^^^^^^^^

Shouldn't that be CAfxDialogImpl? If so, please reconsider whether you want
to cut'n'paste so that people know what your code is or retype things so
people have to guess. Also, in C++ the compiler doesn't care where (in what
kind of file) code is written, so it doesn't matter that you did something
in a .cpp file.

> The actual code is converted from VC++6.0 to VS2008 using project
> conversion wizard in VS2008.

This used to compile in VC6 but doesn't in VS2008?

Uli


--
C++ FAQ: http://parashift.com/c++-faq-lite

Sator Laser GmbH
Geschäftsführer: Thorsten Föcking, Amtsgericht Hamburg HR B62 932
From: SM on
Hi,
I'm unable to compile the code in VS2008.

Thanks,
Sony
On Apr 30, 3:03 pm, Ulrich Eckhardt <eckha...(a)satorlaser.com> wrote:
> SM wrote:
> > typedef struct{
> > int a;
> > int b;
> > }TestStructure;
>
> struct TestStructure { ... };
>
> Drop the 'typedef' to assign a typename to an anonymous structure.
>
> > class CTestStructureDialog :
> > public CAxDialogImpl<CTestStructureDialog>
> > {
> > public:
> > TestStructure *t2={0,1}
> > };
> > I'm getting error as below
> > error C2059: syntax error : '{'
> > error C2334: unexpected token(s) preceding '{'; skipping apparent
> > function body
> > How to initialize the pointer structure?
>
> Two things:
> 1. You can only initialise a pointer to a pointer value, while you are
> giving two integers here to (probably) initialise what the pointer points
> to. You probably don't want a pointer. As a general rule, don't use
> pointers.
> 2. Initialise things in the constructor's "initialiser list", which should
> be explained in every C++ book. Note though that you can't initialise an
> aggregate like TestStructure unless it has a constructor itself.
>
> > public CAxDialogImpl<CTest1>, public CUpdateUI<CTest1>,
>
>          ^^^^^^^^^^^^^
>
> Shouldn't that be CAfxDialogImpl? If so, please reconsider whether you want
> to cut'n'paste so that people know what your code is or retype things so
> people have to guess. Also, in C++ the compiler doesn't care where (in what
> kind of file) code is written, so it doesn't matter that you did something
> in a .cpp file.
>
> > The actual code is converted from VC++6.0 to VS2008 using project
> > conversion wizard in VS2008.
>
> This used to compile in VC6 but doesn't in VS2008?
>
> Uli
>
> --
> C++ FAQ:http://parashift.com/c++-faq-lite
>
> Sator Laser GmbH
> Geschäftsführer: Thorsten Föcking, Amtsgericht Hamburg HR B62 932

From: Ulrich Eckhardt on
SM wrote:
> I'm unable to compile the code in VS2008.

That was understood, what about the other questions?

Uli