How to compile Greta against VES2008? - visual-c++

I compiled Greta against VES2008, it reports
error C2332: 'class' : missing tag name
error C3306: 'regex::detail::<unnamed-tag>': unnamed class template is not allowed
error C2143: syntax error : missing ';' before '__builtin_alignof'
error C2059: syntax error : '__builtin_alignof'
error C2143: syntax error : missing ';' before '{'
error C2447: '{' : missing function header (old-style formal list?)
relevant source code snippet:
template< typename T >
class alignof
{
struct helper
{
helper();
char m_c;
T m_t;
};
public:
enum { value = sizeof(helper)-sizeof(T) < sizeof(T) ? sizeof(helper)-sizeof(T) : sizeof(T) };
};
after precompiled, it
template< typename T >
class __alignof
{
struct helper
{
helper();
char m_c;
T m_t;
};
public:
enum { value = sizeof(helper)-sizeof(T) < sizeof(T) ? sizeof(helper)-sizeof(T) : sizeof(T) };
};
I have not found answers after googling. what caused this and how to resolve it?

Although alignof does not seem to be a reserved word in VS2008, it's so similar to _alignof that it may be confusing the issue.
Try changing the name of your class to something different.

Related

Linked List Creating head causing error C2143: syntax error : missing ';' before '*'

I am trying to make a linkedList but when I create a Head in a separate ADT with class Node Included in it it produces an error error C2143: syntax error : missing ';' before '*'
This is code for ADT of Node
#include <iostream>
#include "LinkedList.h"
using namespace std;
class Node
{
friend LinkedList;
protected:
int data;
Node *next;
public:
Node(int d =-999, Node *n = NULL);
//Mutators
void setData(int d);
void setNext(Node *n);
//Accessors
int getData ();
Node *getNext();
};
This is code for ADT LinkedList
class LinkedList
{
private:
Node *head; //This line is causing that particular error
public:
//some lines of code
};
I am completely lost tried every possible solution but can't figure out what's actually going wrong here.

static constexpr member in-class initialization

Could anyone help me find out what is wrong with in-class initialization of
static constexpr member varaible like in the code below ?
Using Visual Studio 2013
struct hg {
public:
static constexpr float asd = 9.0f;
};
int main() {
return 0;
}
The above code gives the following errors :
Error 1
error C2144: syntax error : 'float' should be preceded by ';'
Error 2
error C4430: missing type specifier - int assumed. Note: C++ does not support default-int

Visual C++ : C2143

why would the following sniplet
#include <atlcom.h>
...
class FormRegionWrapper;
...
// Errorsource :
typedef IDispEventSimpleImpl
<2, FormRegionWrapper, &__uuidof(FormRegionEvents)>
FormRegionEventSink;
will give me the following errors:
// Error ouput:
error C2143: syntax error : missing ';' before '<'
error C4430: missing type specifier - int assumed.
Note: C++ does not support default-int
?!?
(The sniplet is taken from here : Building a C++ Add-in for Outlook 2010 ). My environment : MS Visual Studio 2012 Professinal, and Windows 7-64.
PS 1: Here what the help says about the IDispEventSimpleImpl :
// Help IDispEventSimpleImpl Class : This class provides implementations of
// the IDispatch methods, without getting type information from a type library.
// template <
// UINT nID,
// class T,
// const IID* pdiid
// >
// class ATL_NO_VTABLE IDispEventSimpleImpl :
// public _IDispEventLocator<nID, pdiid>
//
// Requirements
// -------------------
// Header: atlcom.h
Have you included atlcom.h so that the template IDispEventSimpleImpl is defined? Are the declarations of other classes (I assume written by you) used in the template declaration available? And i don't think that forward definition of FormRegionWrapper is enough, can you try and include the declaration of that class, so that template sees it?
UPDATE
Not sure if this will help much, but I replaced the source of FormRegionWrapper.h with the colde below (example from the MSDN page on IDispEventSimpleImpl:
#pragma once
#include "stdafx.h"
#include <vector>
#include <algorithm>
_ATL_FUNC_INFO Event1Info1 = { CC_CDECL, VT_EMPTY, 1, { VT_I4 } };
class CEventHandler;
typedef IDispEventSimpleImpl <1234, CEventHandler, &__uuidof(IDispatch)>
DummySink;
class CEventHandler : public DummySink
{
public:
BEGIN_SINK_MAP(CEventHandler)
SINK_ENTRY_INFO(1234, __uuidof(IDispatch), 1, OnEvent1, &Event1Info1)
END_SINK_MAP()
void __stdcall OnEvent1(LONG l)
{
//ATLASSERT(l == 445533);
if (l != 445533)
OutputDebugString(L"l is not 445533\n");
}
HRESULT Advise1234(IUnknown * punk) {
return IDispEventSimpleImpl<1234, CEventHandler, &__uuidof(IDispatch)>::DispEventAdvise(punk);
}
};
If this works, you can safely assume that the template is being included correctly.
Add this line after the #include directives in FormRegionWrapper.h:
using namespace ATL;

Why is this C++ program giving compile-time error eventhough forward declaration is supplied?

Code:
#include<iostream>
using namespace std;
class MyClassOne;
class MyClassTwo
{
int myInteger;
float myFloat;
public:
void SetData(int myIntegerParameter, float myFloatParameter)
{
myInteger = myIntegerParameter;
myFloat = myFloatParameter;
}
void Show(MyClassOne myObjectParameter)
{
cout<<"MyClassOne..."<<"\n";
cout<<myObjectParameter.myInteger<<"\n";
cout<<myObjectParameter.myFloat<<"\n";
cout<<"MyClassTwo..."<<"\n";
cout<<myInteger<<"\n";
cout<<myFloat<<"\n";
}
};
class MyClassOne
{
int myInteger;
float myFloat;
public:
void SetData(int myIntegerParameter, float myFloatParameter)
{
myInteger = myIntegerParameter;
myFloat = myFloatParameter;
}
friend void MyClassTwo :: Show(MyClassOne);
};
int main()
{
MyClassOne myObjectOne;
myObjectOne.SetData(10, 10.5);
MyClassTwo myObjectTwo;
myObjectTwo.SetData(20, 20.5);
myObjectTwo.Show(myObjectOne);
return 0;
}
Error Message:
1>friend_function.cpp(22) : error C2027: use of undefined type 'MyClassOne'
1>friend_function.cpp(6) : see declaration of 'MyClassOne'
1>friend_function.cpp(22) : error C2228: left of '.myInteger' must have
class/struct/union
1>friend_function.cpp(23) : error C2027: use of undefined type 'MyClassOne'
1>friend_function.cpp(6) : see declaration of 'MyClassOne'
1>friend_function.cpp(23) : error C2228: left of '.myFloat' must have
class/struct/union
1>Generating Code...
1>Build log was saved at "file://Debug\BuildLog.htm"
1>Problem_05___Friend_Function - 4 error(s), 0 warning(s)
========== Rebuild All: 0 succeeded, 1 failed, 0 skipped ==========
MyClassTwo::Show expects a complete definition of MyClassOne.
Move the body of the Show method to after the definition of MyClassOne and it will work.
Because you can't use a forward declaration except for providing pointers to objects.
You can do the following instead:
//MyClassTwo.h
//declaration in header
void Show(MyClassOne* myObjectParameter);
and move the implementation to the cpp file:
//MyClassTwo.cpp
void MyClassTwo::Show(MyClassOne* myObjectParameter);
{
cout<<"MyClassOne..."<<"\n";
cout<<myObjectParameter->myInteger<<"\n";
cout<<myObjectParameter->myFloat<<"\n";
cout<<"MyClassTwo..."<<"\n";
cout<<myInteger<<"\n";
cout<<myFloat<<"\n";
}
The forward declaration allows you to use pointer as they are all the same size. Using an actual instance would mean you'd have to know the size of the object since it will be pushed on the method's argument stack. But you don't know the size since its declaration wasn't encountered yet. Changing the order of declaration will give an error when declaring the friend.
Separation of implementation and declaration is the way to go.
To access members of a class you need its definition, not just its declaration.
Specifically, you need to have the MyClassOne definition above the MyClassTwo definition, if you expect MyClassTwo to access members of MyClassOne.
Also, it would be a good idea to pass MyClassOne as a reference to const to the MyClassTwo::Show() member function. Therefore, you should redefine it as:
void Show(const MyClassOne &myObjectParameter)

C++ template : OKay for VC2005SP1, gcc bails out?

I'm puzzled here, and kindly request your help.
VC2005SP1 swallows this (stripped out) code but gcc 4.0.1 bails out... Please point me the obvious mistake ?
TIA!
template<typename BCT, typename UIDT>
class Factory
{
public:
template<typename CT>
bool Register(UIDT UniqueID)
{
if (UniqueID > 10)
return(false);
CreateObject2<BCT, CT>;
return(true);
}
};
template <typename MC, typename MT>
class Manager : public Factory<MC, MT>
{
public:
bool RegisterType(const MT Type, const std::string TypeName)
{
return Factory<MC, MT>::Register<MC>(Type); // gcc claims "expected primary-expression before '>' at this point
}
};
VS is being kind.
return Factory<MC, MT>::template Register<MC>(Type); should work under both compilers.

Resources