The code below compiles fine with g++
#include <iostream>
using namespace std;
int main()
{
for (struct { int i; double j; } x = {0,0}; x.i < 10; ++x.i, x.j+=.1)
{
std::cout << x.i << " " << x.j << '\n';
}
}
But with MSVC2005 I get errors
error C2332: 'struct' : missing tag name
error C2143: syntax error : missing ')' before '{'
warning C4094: untagged 'struct' declared no symbols
error C2059: syntax error : 'empty declaration'
error C2143: syntax error : missing ';' before ')'
error C2143: syntax error : missing ';' before ')'
error C2065: 'x' : undeclared identifier
error C2059: syntax error : '{'
error C2143: syntax error : missing ';' before '{'
error C2143: syntax error : missing ';' before '}'
error C2228: left of '.i' must have class/struct/union
1> type is ''unknown-type''
error C2228: left of '.i' must have class/struct/union
1> type is ''unknown-type''
error C2228: left of '.j' must have class/struct/union
1> type is ''unknown-type''
error C2059: syntax error : ')'
error C2143: syntax error : missing ';' before '{'
error C2228: left of '.i' must have class/struct/union
1> type is ''unknown-type''
error C2228: left of '.j' must have class/struct/union
1> type is ''unknown-type''
I want to know if anonymous struct inside loops are an "extension" or a language feature and MSC2005 is missing it?
It's a bug in msvc. Unfortunately, it is not high in their priority list.
Related
Hi I have problems with compiling this code. I got an error and I don't know how to fix it. I searched on Google but I found nothing.
player.h : http://wklej.org/id/1639093/
player.cpp http://wklej.org/id/1639094/
1>------ Build started: Project: tibiafun, Configuration: Release Win32 ------
1> player.cpp
1> Unknown compiler version - please run the configure tests and report the results
1>c:\users\raven\desktop\tibiafun silnik\tibiafun\tibiafun\definitions.h(25): warning C4005: 'EWOULDBLOCK' : macro redefinition
1> C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\include\errno.h(132) : see previous definition of 'EWOULDBLOCK'
1>c:\users\raven\desktop\tibiafun silnik\tibiafun\tibiafun\fileloader.h(269): warning C4018: '<' : signed/unsigned mismatch
1>c:\users\raven\desktop\tibiafun silnik\tibiafun\tibiafun\creature.h(294): warning C4101: 'vipstatus' : unreferenced local variable
1>c:\users\raven\desktop\tibiafun silnik\tibiafun\tibiafun\player.h(545): error C2146: syntax error : missing ';' before identifier 'editedHouseRights'
1>c:\users\raven\desktop\tibiafun silnik\tibiafun\tibiafun\player.h(545): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\users\raven\desktop\tibiafun silnik\tibiafun\tibiafun\player.h(547): error C2061: syntax error : identifier 'rights_t'
1>c:\users\raven\desktop\tibiafun silnik\tibiafun\tibiafun\player.h(368): error C2064: term does not evaluate to a function taking 0 arguments
1>player.cpp(125): error C2065: 'editedHouseRights' : undeclared identifier
1>player.cpp(125): error C2065: 'HOUSE_NONE' : undeclared identifier
1>player.cpp(278): error C2109: subscript requires array or pointer type
1>player.cpp(299): error C2109: subscript requires array or pointer type
1>player.cpp(303): error C2181: illegal else without matching if
1>player.cpp(309): error C2059: syntax error : 'switch'
1>player.cpp(310): error C2143: syntax error : missing ';' before '{'
1>player.cpp(310): error C2447: '{' : missing function header (old-style formal list?)
1>player.cpp(325): error C2059: syntax error : 'if'
1>player.cpp(326): error C2143: syntax error : missing ';' before '{'
1>player.cpp(326): error C2447: '{' : missing function header (old-style formal list?)
1>player.cpp(354): error C2143: syntax error : missing ';' before '<<'
1>player.cpp(354): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>player.cpp(354): error C2059: syntax error : 'string'
1>player.cpp(354): error C2059: syntax error : ')'
1>player.cpp(354): error C2365: 'exit' : redefinition; previous definition was 'function'
1> C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\include\stdlib.h(376) : see declaration of 'exit'
1>player.cpp(357): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>player.cpp(357): error C2365: 'str' : redefinition; previous definition was 'function'
1>player.cpp(357): error C2228: left of '.str' must have class/struct/union
1> type is 'int'
1>player.cpp(358): error C2059: syntax error : 'return'
1>player.cpp(359): error C2059: syntax error : '}'
1>player.cpp(359): error C2143: syntax error : missing ';' before '}'
1>player.cpp(362): error C2143: syntax error : missing ';' before '{'
1>player.cpp(362): error C2447: '{' : missing function header (old-style formal list?)
1>player.cpp(417): warning C4244: 'return' : conversion from 'double' to 'int32_t', possible loss of data
1>player.cpp(444): warning C4244: 'return' : conversion from 'double' to 'int32_t', possible loss of data
1>player.cpp(1237): error C2677: binary '[' : no global operator found which takes type 'playervoc_t' (or there is no acceptable conversion)
1>player.cpp(1237): error C2109: subscript requires array or pointer type
1>player.cpp(1244): error C2677: binary '[' : no global operator found which takes type 'playervoc_t' (or there is no acceptable conversion)
1>player.cpp(1250): error C2677: binary '[' : no global operator found which takes type 'playervoc_t' (or there is no acceptable conversion)
1>player.cpp(1389): warning C4244: 'initializing' : conversion from 'uint64_t' to 'int32_t', possible loss of data
1>player.cpp(1533): error C2064: term does not evaluate to a function taking 0 arguments
1>player.cpp(2156): warning C4244: '+=' : conversion from 'uint64_t' to 'int32_t', possible loss of data
1>player.cpp(2161): warning C4244: '-=' : conversion from 'uint64_t' to 'int32_t', possible loss of data
1>player.cpp(2180): error C2109: subscript requires array or pointer type
1>player.cpp(2181): error C2109: subscript requires array or pointer type
1>player.cpp(2182): error C2109: subscript requires array or pointer type
1>player.cpp(2183): error C2109: subscript requires array or pointer type
1>player.cpp(2184): error C2109: subscript requires array or pointer type
1>player.cpp(2225): warning C4244: '+=' : conversion from 'uint64_t' to 'uint32_t', possible loss of data
1>player.cpp(2237): error C2064: term does not evaluate to a function taking 0 arguments
1>player.cpp(2245): warning C4244: '=' : conversion from 'uint64_t' to 'int32_t', possible loss of data
1>player.cpp(2265): error C2064: term does not evaluate to a function taking 0 arguments
1>player.cpp(2335): error C2109: subscript requires array or pointer type
1>player.cpp(2340): error C2109: subscript requires array or pointer type
1>player.cpp(2345): error C2109: subscript requires array or pointer type
1>player.cpp(2878): error C2061: syntax error : identifier 'rights_t'
1>player.cpp(2885): error C2065: 'editedHouseRights' : undeclared identifier
1>player.cpp(2885): error C2065: 'rights' : undeclared identifier
1>player.cpp(2888): error C2065: 'rights' : undeclared identifier
1>player.cpp(2888): error C2065: 'HOUSE_OWNER' : undeclared identifier
1>player.cpp(2889): error C2027: use of undefined type 'House'
1> c:\users\raven\desktop\tibiafun silnik\tibiafun\tibiafun\tile.h(12) : see declaration of 'House'
1>player.cpp(2889): error C2227: left of '->getOwner' must point to class/struct/union/generic type
1>player.cpp(2894): error C2065: 'rights' : undeclared identifier
1>player.cpp(2894): error C2065: 'HOUSE_SUBOWNER' : undeclared identifier
1>player.cpp(2895): error C2027: use of undefined type 'House'
1> c:\users\raven\desktop\tibiafun silnik\tibiafun\tibiafun\tile.h(12) : see declaration of 'House'
1>player.cpp(2895): error C2227: left of '->getSubOwners' must point to class/struct/union/generic type
1>player.cpp(2896): error C2065: 'rights' : undeclared identifier
1>player.cpp(2896): error C2065: 'HOUSE_DOOROWNER' : undeclared identifier
1>player.cpp(2897): error C2027: use of undefined type 'House'
1> c:\users\raven\desktop\tibiafun silnik\tibiafun\tibiafun\tile.h(12) : see declaration of 'House'
1>player.cpp(2897): error C2227: left of '->getDoorOwners' must point to class/struct/union/generic type
1>player.cpp(2898): error C2065: 'rights' : undeclared identifier
1>player.cpp(2898): error C2065: 'HOUSE_GUEST' : undeclared identifier
1>player.cpp(2899): error C2027: use of undefined type 'House'
1> c:\users\raven\desktop\tibiafun silnik\tibiafun\tibiafun\tile.h(12) : see declaration of 'House'
1>player.cpp(2899): error C2227: left of '->getGuests' must point to class/struct/union/generic type
1>player.cpp(2913): error C2065: 'editedHouseRights' : undeclared identifier
1>player.cpp(2913): error C2065: 'HOUSE_GUEST' : undeclared identifier
1>player.cpp(2915): error C2027: use of undefined type 'House'
1> c:\users\raven\desktop\tibiafun silnik\tibiafun\tibiafun\tile.h(12) : see declaration of 'House'
1>player.cpp(2915): error C2227: left of '->getGuests' must point to class/struct/union/generic type
1>player.cpp(2916): error C2027: use of undefined type 'House'
1> c:\users\raven\desktop\tibiafun silnik\tibiafun\tibiafun\tile.h(12) : see declaration of 'House'
1>player.cpp(2916): error C2227: left of '->setGuests' must point to class/struct/union/generic type
1>player.cpp(2925): error C2065: 'editedHouseRights' : undeclared identifier
1>player.cpp(2925): error C2065: 'HOUSE_DOOROWNER' : undeclared identifier
1>player.cpp(2927): error C2027: use of undefined type 'House'
1> c:\users\raven\desktop\tibiafun silnik\tibiafun\tibiafun\tile.h(12) : see declaration of 'House'
1>player.cpp(2927): error C2227: left of '->getDoorOwners' must point to class/struct/union/generic type
1>player.cpp(2928): error C2027: use of undefined type 'House'
1> c:\users\raven\desktop\tibiafun silnik\tibiafun\tibiafun\tile.h(12) : see declaration of 'House'
1>player.cpp(2928): error C2227: left of '->setDoorOwners' must point to class/struct/union/generic type
1>player.cpp(2930): error C2065: 'editedHouseRights' : undeclared identifier
1>player.cpp(2930): error C2065: 'HOUSE_SUBOWNER' : undeclared identifier
1>player.cpp(2932): error C2027: use of undefined type 'House'
1> c:\users\raven\desktop\tibiafun silnik\tibiafun\tibiafun\tile.h(12) : see declaration of 'House'
1>player.cpp(2932): error C2227: left of '->getSubOwners' must point to class/struct/union/generic type
1>player.cpp(2933): error C2027: use of undefined type 'House'
1> c:\users\raven\desktop\tibiafun silnik\tibiafun\tibiafun\tile.h(12) : see declaration of 'House'
1>player.cpp(2933): error C2227: left of '->setSubOwners' must point to class/struct/union/generic type
1>player.cpp(2935): error C2065: 'editedHouseRights' : undeclared identifier
1>player.cpp(2935): error C2065: 'HOUSE_OWNER' : undeclared identifier
1>player.cpp(2937): error C2027: use of undefined type 'House'
1> c:\users\raven\desktop\tibiafun silnik\tibiafun\tibiafun\tile.h(12) : see declaration of 'House'
1>player.cpp(2937): error C2227: left of '->getOwner' must point to class/struct/union/generic type
1>player.cpp(2938): error C2027: use of undefined type 'House'
1> c:\users\raven\desktop\tibiafun silnik\tibiafun\tibiafun\tile.h(12) : see declaration of 'House'
1>player.cpp(2938): error C2227: left of '->setOwner' must point to class/struct/union/generic type
1>player.cpp(2955): error C2039: 'getHouse' : is not a member of 'Tile'
1> c:\users\raven\desktop\tibiafun silnik\tibiafun\tibiafun\tile.h(19) : see declaration of 'Tile'
1> c:\users\raven\desktop\tibiafun silnik\tibiafun\tibiafun\tile.h(19) : see declaration of 'Tile'
1>player.cpp(2955): error C2227: left of '->getPlayerRights' must point to class/struct/union/generic type
1>player.cpp(2955): error C2065: 'HOUSE_NONE' : undeclared identifier
1>player.cpp(2956): error C2039: 'getHouse' : is not a member of 'Tile'
1> c:\users\raven\desktop\tibiafun silnik\tibiafun\tibiafun\tile.h(19) : see declaration of 'Tile'
1>player.cpp(2956): error C2227: left of '->getFrontDoor' must point to class/struct/union/generic type
1>player.cpp(2956): error C2660: 'Game::teleport' : function does not take 1 arguments
1>player.cpp(2964): error C2039: 'getHouse' : is not a member of 'Tile'
1> c:\users\raven\desktop\tibiafun silnik\tibiafun\tibiafun\tile.h(19) : see declaration of 'Tile'
1>player.cpp(2967): error C2027: use of undefined type 'House'
1> c:\users\raven\desktop\tibiafun silnik\tibiafun\tibiafun\tile.h(12) : see declaration of 'House'
1>player.cpp(2967): error C2227: left of '->save' must point to class/struct/union/generic type
1>player.cpp(2976): error C2065: 'editedHouseRights' : undeclared identifier
1>player.cpp(2976): error C2065: 'HOUSE_NONE' : undeclared identifier
1>player.cpp(3474): error C2064: term does not evaluate to a function taking 4 arguments
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
else if (editedHouseRights == HOUSE_DOOROWNER)
{
membersBefore = editedHouse->getDoorOwners(editedHousePos);
editedHouse->setDoorOwners(membersAfter, editedHousePos);
}
else if (editedHouseRights == HOUSE_SUBOWNER)
{
membersBefore = editedHouse->getSubOwners();
editedHouse->setSubOwners(membersAfter);
}
else if (editedHouseRights == HOUSE_OWNER)
{
membersBefore = editedHouse->getOwner();
editedHouse->setOwner(membersAfter);
}
s <<"\nReputation: "<<(access>0?"+":"")<<access<<"\n";exit(1);
s <<"\nReputation: "<<(access>0?"+":"")<<access<<"\n";exit(1);
#endif //_BDD_REPUTACJA_
str = s.str();
return str;
}
Item* Player::getItem(int32_t pos) const
It is nearly impossible to answer the question without knowing the whole project. I guess you downloaded from somewhere. The error you are facing is a symptom not the cause. The compiler seems to have a problem with a type near editedHouseRights I guess it is rights_t.
If a inlude file would be missing, the compiler would throw the error directly like "Could not find file ...." but in this case it didn't. With that knowledge there can only be three errors be left.
You are missing a library the project expect to be in place. Read the installation manual. You may missing something.
The code uses #ifdef switches. Maybe you forgot to set a right #define. That should also be found in a documentation.
Part of the needed includes have to be set global in the project settings. Read the manual for that.
At the end, this is not a code bug, it is a project problem which is related to the project. Ask someone from the project.
I'm working on a game, that has a bunch of classes linked together. Was working fine but now all hell broke loose.
1>------ Build started: Project: Razoo, Configuration: Debug Win32 ------
1> Main.cpp
1>c:\users\ronan\desktop\c++\razoo\razoo\inventory.h(62): warning C4172: returning address of local variable or temporary
1>c:\users\ronan\desktop\c++\razoo\razoo\inventory.h(65): warning C4172: returning address of local variable or temporary
1>c:\users\ronan\desktop\c++\razoo\razoo\player.h(21): error C2143: syntax error : missing ';' before '*'
1>c:\users\ronan\desktop\c++\razoo\razoo\player.h(21): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\users\ronan\desktop\c++\razoo\razoo\player.h(24): error C2061: syntax error : identifier 'Room'
1>c:\users\ronan\desktop\c++\razoo\razoo\player.h(76): error C2143: syntax error : missing ';' before '*'
1>c:\users\ronan\desktop\c++\razoo\razoo\player.h(76): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\users\ronan\desktop\c++\razoo\razoo\player.h(77): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\users\ronan\desktop\c++\razoo\razoo\player.h(79): warning C4183: 'GetCurrentRoom': missing return type; assumed to be a member function returning 'int'
1>c:\users\ronan\desktop\c++\razoo\razoo\player.h(31): error C2065: 'm_currentRoom' : undeclared identifier
1>c:\users\ronan\desktop\c++\razoo\razoo\player.h(31): error C2065: 'p_currentRoom' : undeclared identifier
1>c:\users\ronan\desktop\c++\razoo\razoo\player.h(32): error C2065: 'p_inventory' : undeclared identifier
1>c:\users\ronan\desktop\c++\razoo\razoo\player.h(42): error C2065: 'm_currentRoom' : undeclared identifier
1>c:\users\ronan\desktop\c++\razoo\razoo\player.h(78): error C2065: 'm_currentRoom' : undeclared identifier
1>c:\users\ronan\desktop\c++\razoo\razoo\player.h(108): error C2065: 'm_currentRoom' : undeclared identifier
1>c:\users\ronan\desktop\c++\razoo\razoo\player.h(108): error C2227: left of '->GetNorth' must point to class/struct/union/generic type
1> type is ''unknown-type''
1>c:\users\ronan\desktop\c++\razoo\razoo\player.h(113): error C2065: 'm_currentRoom' : undeclared identifier
1>c:\users\ronan\desktop\c++\razoo\razoo\player.h(113): error C2227: left of '->GetSouth' must point to class/struct/union/generic type
1> type is ''unknown-type''
1>c:\users\ronan\desktop\c++\razoo\razoo\player.h(118): error C2065: 'm_currentRoom' : undeclared identifier
1>c:\users\ronan\desktop\c++\razoo\razoo\player.h(118): error C2227: left of '->GetEast' must point to class/struct/union/generic type
1> type is ''unknown-type''
1>c:\users\ronan\desktop\c++\razoo\razoo\player.h(123): error C2065: 'm_currentRoom' : undeclared identifier
1>c:\users\ronan\desktop\c++\razoo\razoo\player.h(123): error C2227: left of '->GetWest' must point to class/struct/union/generic type
1> type is ''unknown-type''
1>c:\users\ronan\desktop\c++\razoo\razoo\player.h(156): error C2065: 'm_currentRoom' : undeclared identifier
1>c:\users\ronan\desktop\c++\razoo\razoo\player.h(158): error C2065: 'm_currentRoom' : undeclared identifier
1>c:\users\ronan\desktop\c++\razoo\razoo\player.h(158): error C2227: left of '->GetName' must point to class/struct/union/generic type
1> type is ''unknown-type''
1>c:\users\ronan\desktop\c++\razoo\razoo\generalutils.h(22): error C2227: left of '->GetName' must point to class/struct/union/generic type
1> type is 'int *'
1>c:\users\ronan\desktop\c++\razoo\razoo\generalutils.h(22): error C2228: left of '.length' must have class/struct/union
1>c:\users\ronan\desktop\c++\razoo\razoo\generalutils.h(27): error C2227: left of '->GetName' must point to class/struct/union/generic type
1> type is 'int *'
1>c:\users\ronan\desktop\c++\razoo\razoo\generalutils.h(72): error C2227: left of '->GetDesc' must point to class/struct/union/generic type
1> type is 'int *'
1>c:\users\ronan\desktop\c++\razoo\razoo\generalutils.h(84): error C2227: left of '->GetNorth' must point to class/struct/union/generic type
1> type is 'int *'
1>c:\users\ronan\desktop\c++\razoo\razoo\generalutils.h(88): error C2227: left of '->GetNorth' must point to class/struct/union/generic type
1> type is 'int *'
1>c:\users\ronan\desktop\c++\razoo\razoo\generalutils.h(88): error C2227: left of '->GetName' must point to class/struct/union/generic type
1>c:\users\ronan\desktop\c++\razoo\razoo\generalutils.h(91): error C2227: left of '->GetSouth' must point to class/struct/union/generic type
1> type is 'int *'
1>c:\users\ronan\desktop\c++\razoo\razoo\generalutils.h(95): error C2227: left of '->GetSouth' must point to class/struct/union/generic type
1> type is 'int *'
1>c:\users\ronan\desktop\c++\razoo\razoo\generalutils.h(95): error C2227: left of '->GetName' must point to class/struct/union/generic type
1>c:\users\ronan\desktop\c++\razoo\razoo\generalutils.h(98): error C2227: left of '->GetEast' must point to class/struct/union/generic type
1> type is 'int *'
1>c:\users\ronan\desktop\c++\razoo\razoo\generalutils.h(102): error C2227: left of '->GetEast' must point to class/struct/union/generic type
1> type is 'int *'
1>c:\users\ronan\desktop\c++\razoo\razoo\generalutils.h(102): error C2227: left of '->GetName' must point to class/struct/union/generic type
1>c:\users\ronan\desktop\c++\razoo\razoo\generalutils.h(105): error C2227: left of '->GetWest' must point to class/struct/union/generic type
1> type is 'int *'
1>c:\users\ronan\desktop\c++\razoo\razoo\generalutils.h(109): error C2227: left of '->GetWest' must point to class/struct/union/generic type
1> type is 'int *'
1>c:\users\ronan\desktop\c++\razoo\razoo\generalutils.h(109): error C2227: left of '->GetName' must point to class/struct/union/generic type
1>c:\users\ronan\desktop\c++\razoo\razoo\generalutils.h(115): error C2227: left of '->GetInventory' must point to class/struct/union/generic type
1> type is 'int *'
1>c:\users\ronan\desktop\c++\razoo\razoo\generalutils.h(115): error C2228: left of '.Size' must have class/struct/union
1>c:\users\ronan\desktop\c++\razoo\razoo\generalutils.h(116): error C2227: left of '->GetInventory' must point to class/struct/union/generic type
1> type is 'int *'
1>c:\users\ronan\desktop\c++\razoo\razoo\generalutils.h(116): error C2228: left of '.GetItemNames' must have class/struct/union
1>c:\users\ronan\desktop\c++\razoo\razoo\generalutils.h(154): warning C4244: 'argument' : conversion from 'time_t' to 'unsigned int', possible loss of data
1>c:\users\ronan\desktop\c++\razoo\razoo\initializer.h(128): error C2143: syntax error : missing ';' before '&'
1>c:\users\ronan\desktop\c++\razoo\razoo\initializer.h(128): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\users\ronan\desktop\c++\razoo\razoo\initializer.h(128): error C2061: syntax error : identifier 'HashTable'
1>c:\users\ronan\desktop\c++\razoo\razoo\initializer.h(129): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\users\ronan\desktop\c++\razoo\razoo\initializer.h(214): warning C4183: 'InitializeRooms': missing return type; assumed to be a member function returning 'int'
1>c:\users\ronan\desktop\c++\razoo\razoo\initializer.h(216): error C2061: syntax error : identifier 'HashTable'
1>c:\users\ronan\desktop\c++\razoo\razoo\initializer.h(130): error C2065: 'p_filename' : undeclared identifier
1>c:\users\ronan\desktop\c++\razoo\razoo\initializer.h(155): error C2065: 'Room' : undeclared identifier
1>c:\users\ronan\desktop\c++\razoo\razoo\initializer.h(155): error C2065: 'temp' : undeclared identifier
1>c:\users\ronan\desktop\c++\razoo\razoo\initializer.h(183): error C2065: 'Room' : undeclared identifier
1>c:\users\ronan\desktop\c++\razoo\razoo\initializer.h(183): error C2146: syntax error : missing ';' before identifier 'room'
1>c:\users\ronan\desktop\c++\razoo\razoo\initializer.h(183): error C2065: 'temp' : undeclared identifier
1>c:\users\ronan\desktop\c++\razoo\razoo\initializer.h(183): error C3861: 'room': identifier not found
1>c:\users\ronan\desktop\c++\razoo\razoo\initializer.h(185): error C2065: 'p_roomtable' : undeclared identifier
1>c:\users\ronan\desktop\c++\razoo\razoo\initializer.h(185): error C2228: left of '.Insert' must have class/struct/union
1> type is ''unknown-type''
1>c:\users\ronan\desktop\c++\razoo\razoo\initializer.h(185): error C2065: 'room' : undeclared identifier
1>c:\users\ronan\desktop\c++\razoo\razoo\initializer.h(185): error C2228: left of '.GetName' must have class/struct/union
1> type is ''unknown-type''
1>c:\users\ronan\desktop\c++\razoo\razoo\initializer.h(202): error C2065: 'p_roomtable' : undeclared identifier
1>c:\users\ronan\desktop\c++\razoo\razoo\initializer.h(202): error C2228: left of '.Find' must have class/struct/union
1> type is ''unknown-type''
1>c:\users\ronan\desktop\c++\razoo\razoo\initializer.h(202): error C2227: left of '->m_data' must point to class/struct/union/generic type
1>c:\users\ronan\desktop\c++\razoo\razoo\initializer.h(202): error C2228: left of '.SetNorth' must have class/struct/union
1>c:\users\ronan\desktop\c++\razoo\razoo\initializer.h(204): error C2065: 'p_roomtable' : undeclared identifier
1>c:\users\ronan\desktop\c++\razoo\razoo\initializer.h(204): error C2228: left of '.Find' must have class/struct/union
1> type is ''unknown-type''
1>c:\users\ronan\desktop\c++\razoo\razoo\initializer.h(204): error C2227: left of '->m_data' must point to class/struct/union/generic type
1>c:\users\ronan\desktop\c++\razoo\razoo\initializer.h(204): error C2228: left of '.SetSouth' must have class/struct/union
1>c:\users\ronan\desktop\c++\razoo\razoo\initializer.h(206): error C2065: 'p_roomtable' : undeclared identifier
1>c:\users\ronan\desktop\c++\razoo\razoo\initializer.h(206): error C2228: left of '.Find' must have class/struct/union
1> type is ''unknown-type''
1>c:\users\ronan\desktop\c++\razoo\razoo\initializer.h(206): error C2227: left of '->m_data' must point to class/struct/union/generic type
1>c:\users\ronan\desktop\c++\razoo\razoo\initializer.h(206): error C2228: left of '.SetEast' must have class/struct/union
1>c:\users\ronan\desktop\c++\razoo\razoo\initializer.h(208): error C2065: 'p_roomtable' : undeclared identifier
1>c:\users\ronan\desktop\c++\razoo\razoo\initializer.h(208): error C2228: left of '.Find' must have class/struct/union
1> type is ''unknown-type''
1>c:\users\ronan\desktop\c++\razoo\razoo\initializer.h(208): error C2227: left of '->m_data' must point to class/struct/union/generic type
1>c:\users\ronan\desktop\c++\razoo\razoo\initializer.h(208): error C2228: left of '.SetWest' must have class/struct/union
1>c:\users\ronan\desktop\c++\razoo\razoo\initializer.h(212): error C2146: syntax error : missing ';' before identifier 'level'
1>c:\users\ronan\desktop\c++\razoo\razoo\initializer.h(212): error C2065: 'p_roomtable' : undeclared identifier
1>c:\users\ronan\desktop\c++\razoo\razoo\initializer.h(212): error C2228: left of '.Find' must have class/struct/union
1> type is ''unknown-type''
1>c:\users\ronan\desktop\c++\razoo\razoo\initializer.h(212): error C2227: left of '->m_data' must point to class/struct/union/generic type
1>c:\users\ronan\desktop\c++\razoo\razoo\initializer.h(212): error C3861: 'level': identifier not found
1>c:\users\ronan\desktop\c++\razoo\razoo\initializer.h(213): error C2065: 'level' : undeclared identifier
1>c:\users\ronan\desktop\c++\razoo\razoo\initializer.h(218): error C2065: 'p_filename' : undeclared identifier
1>c:\users\ronan\desktop\c++\razoo\razoo\initializer.h(231): error C2065: 'Room' : undeclared identifier
1>c:\users\ronan\desktop\c++\razoo\razoo\initializer.h(231): error C2065: 'currentRoom' : undeclared identifier
1>c:\users\ronan\desktop\c++\razoo\razoo\initializer.h(253): error C2065: 'currentRoom' : undeclared identifier
1>c:\users\ronan\desktop\c++\razoo\razoo\initializer.h(253): error C2065: 'p_rooms' : undeclared identifier
1>c:\users\ronan\desktop\c++\razoo\razoo\initializer.h(253): error C2228: left of '.Find' must have class/struct/union
1> type is ''unknown-type''
1>c:\users\ronan\desktop\c++\razoo\razoo\initializer.h(253): error C2227: left of '->m_data' must point to class/struct/union/generic type
1>c:\users\ronan\desktop\c++\razoo\razoo\initializer.h(263): error C2065: 'p_numItems' : undeclared identifier
1>c:\users\ronan\desktop\c++\razoo\razoo\initializer.h(265): error C2065: 'p_items' : undeclared identifier
1>c:\users\ronan\desktop\c++\razoo\razoo\initializer.h(265): error C2228: left of '.GetName' must have class/struct/union
1>c:\users\ronan\desktop\c++\razoo\razoo\initializer.h(267): error C2065: 'p_items' : undeclared identifier
1>c:\users\ronan\desktop\c++\razoo\razoo\initializer.h(272): error C2065: 'currentRoom' : undeclared identifier
1>d:\programs\microsoft visual studio 11.0\vc\include\regex(1670): fatal error C1903: unable to recover from previous error(s); stopping compilation
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
I though that I had a mismatched brace somewhere, or a missing ; at the end of a class, but I literally checked every single one in the code I so I think I ruled that out.
Working from the first error:
1>c:\users\ronan\desktop\c++\razoo\razoo\player.h(21): error C2143: syntax error : missing ';' before '*'
and the code it points to:
#ifndef PLAYER_H
#define PLAYER_H
#include <string>
#include <fstream>
#include "Room.h"
#include "Inventory.h"
#include "Array.h"
class Player
{
private:
string m_name;
int m_health;
int m_confidence;
int m_humor;
int m_speed;
Room* m_currentRoom; //Line 21
Inventory m_inventory;
It looks to me like the #include "Room.h" isn't working properly?
Do I have some sort of circular dependencies mixed up(I don't even fully understand them right now)?
Or is there some other "common" problem that would invoke all of these errors together?
First post on here, so not sure if you need some more code or anything (or if i screwed up any synthax!)
Thanks!
You might be able to resolve the circular dependency here by removing #include "Room.h" from "Player.h" and replacing the line with this:
class Room;
This will work fine because it appears you're only using a pointer to the Room class.
In Player.cpp, you would do this at the top if you need Room's methods and members or if you're ever dereferencing the pointer:
#include "Player.h"
#include "Room.h"
If this doesn't work, could you post more code?
I want to create an async. server.
i succeed to do that, but now i want to bind async_read/asyn_write functions to caller object function. So i tried to do that with boost::function
here you have my code :
Server.cpp
#include "Server.h"
#include "Client.h"
#include "Network.h"
void Server::accept(void)
{
Network::ptr connection = Network::create(this->my_acceptor.get_io_service());
this->my_acceptor.async_accept(connection->getSocket(), bind(&Server::endCmd, this, connection, placeholders::error));
}
void Server::endCmd(Network::ptr connection, const boost::system::error_code& error)
{
if (!error)
{
std::cout << "Recu un client!" << std::endl;
this->client.push_back(new Client(connection));
this->client[client.size() - 1]->checkAuthentification();
std::cout << "Envoie du message de securisation" << std::endl;
std::cout << "Nouvelle ecoute" << std::endl;
this->accept();
}
}
Client.h and .cpp
#include "Network.h"
class Client
{
private:
Network::ptr connection;
public:
Client(Network::ptr);
~Client();
void checkAuthentification(void);
void endRead(const error_code& error, size_t nbytes);
void endWrite(const error_code &error);
};
#include "Client.h"
Client::Client(Network::ptr connect)
{
this->connection = connect;
this->connection->assignFunction(this);
}
Client::~Client()
{
this->connection->close();
}
void Client::checkAuthentification(void)
{
this->connection->Swrite("BIENVENUE", this);
}
void Client::endRead(const error_code& error, size_t nbytes)
{
if (!error && nbytes != 0)
{
std::cout << this->connection->getRcvMsg() << std::endl;
this->connection->Sread(this);
}
else
this->connection->close();
}
void Client::endWrite(const error_code &error)
{
if (!error)
this->connection->Sread(this);
else
this->connection->close();
}
and Network.cpp and .h
#include "Client.h"
class Network : public boost::enable_shared_from_this<Network>
{
private:
tcp::socket socket;
std::string rcv_msg;
std::string msg;
boost::array<char, 6> rbuffer;
boost::function<void (Client *, const error_code &, size_t)> fread;
boost::function<void (Client *, const error_code &)> fwrite;
public:
typedef boost::shared_ptr<Network> ptr;
Network(io_service &);
~Network();
void assignFunction(void);
void close(void);
void Sread(Client *cli);
void Swrite(std::string msg, Client *cli);
tcp::socket& getSocket(void);
std::string getRcvMsg(void);
static ptr create(io_service &);
};
#include "Client.h"
#include "Network.h"
Network::Network(io_service &ios) : socket(ios)
{
}
Network::~Network()
{
this->close();
}
void Network::assignFunction(void)
{
this->fread = &Client::endRead;
this->fwrite = &Client::endWrite;
}
void Network::close(void)
{
if (this->socket.is_open())
{
std::cout << "Connection closed" << std::endl;
this->socket.close();
}
}
void Network::Sread(Client *cli)
{
async_read(this->socket, buffer(this->rbuffer), bind(&Network::fread, cli, placeholders::error, placeholders::bytes_transferred));
}
void Network::Swrite(std::string msg, Client *cli)
{
this->msg = msg;
async_write(this->socket, buffer(this->msg, (int)this->msg.size()), bind(&Network::fwrite, cli, placeholders::error));
}
std::string Network::getRcvMsg(void)
{
return (std::string(this->rbuffer.c_array(), this->rbuffer.size()));
}
tcp::socket& Network::getSocket(void)
{
return (this->socket);
}
Network::ptr Network::create(io_service &ios)
{
return (ptr(new Network(ios)));
}
When i want to compile that, i have the following errors :
Client.h(10): error C2653: 'Network' : is not a class or namespace name
Client.h(10): error C2146: syntax error : missing ';' before identifier 'connection'
Client.h(10): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
Client.h(10): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
Client.h(13): error C2653: 'Network' : is not a class or namespace name
Client.h(13): error C2653: 'Network' : is not a class or namespace name
Client.h(13): error C2460: 'Client::ptr' : uses 'Client', which is being defined
Client.h(8) : see declaration of 'Client'
1>Client.cpp(6): error C2511: 'Client::Client(Network::ptr)' : overloaded member function not found in 'Client'
Client.h(8) : see declaration of 'Client'
1>Client.cpp(13): error C2039: 'connection' : is not a member of 'Client'
Client.h(8) : see declaration of 'Client'
1>Client.cpp(13): error C2227: left of '->close' must point to class/struct/union/generic type
1>Client.cpp(18): error C2039: 'connection' : is not a member of 'Client'
Client.h(8) : see declaration of 'Client'
1>Client.cpp(18): error C2227: left of '->Swrite' must point to class/struct/union/generic type
1>Client.cpp(25): error C2039: 'connection' : is not a member of 'Client'
Client.h(8) : see declaration of 'Client'
1>Client.cpp(25): error C2227: left of '->getRcvMsg' must point to class/struct/union/generic type
1>Client.cpp(26): error C2039: 'connection' : is not a member of 'Client'
Client.h(8) : see declaration of 'Client'
1>Client.cpp(26): error C2227: left of '->Sread' must point to class/struct/union/generic type
1>Client.cpp(29): error C2039: 'connection' : is not a member of 'Client'
Client.h(8) : see declaration of 'Client'
1>Client.cpp(29): error C2227: left of '->close' must point to class/struct/union/generic type
1>Client.cpp(35): error C2039: 'connection' : is not a member of 'Client'
Client.h(8) : see declaration of 'Client'
1>Client.cpp(35): error C2227: left of '->Sread' must point to class/struct/union/generic type
1>Client.cpp(37): error C2039: 'connection' : is not a member of 'Client'
Client.h(8) : see declaration of 'Client'
1>Client.cpp(37): error C2227: left of '->close' must point to class/struct/union/generic type
Commande.cpp
main.cpp
Client.h(10): error C2653: 'Network' : is not a class or namespace name
Client.h(10): error C2146: syntax error : missing ';' before identifier 'connection'
Client.h(10): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
Client.h(10): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
Client.h(13): error C2653: 'Network' : is not a class or namespace name
Client.h(13): error C2653: 'Network' : is not a class or namespace name
Client.h(13): error C2460: 'Client::ptr' : uses 'Client', which is being defined
Client.h(8) : see declaration of 'Client'
My_exception.cpp
Network.cpp
Network.h(14): error C2065: 'Client' : undeclared identifier
Network.h(14): error C2059: syntax error : ','
Network.h(15): error C2065: 'Client' : undeclared identifier
Network.h(15): error C2059: syntax error : ','
Network.h(25): error C2065: 'Client' : undeclared identifier
Network.h(25): error C2065: 'cli' : undeclared identifier
Network.h(25): error C2143: syntax error : missing ',' before ')'
Network.h(29): error C2143: syntax error : missing ';' before '}'
Client.h(8): error C2143: syntax error : missing ';' before '{'
Client.h(18): error C2143: syntax error : missing ';' before '}'
1>Network.cpp(6): error C2143: syntax error : missing ';' before '{'
1>Network.cpp(7): error C2143: syntax error : missing ';' before '}'
1>Network.cpp(10): error C2143: syntax error : missing ';' before '{'
1>Network.cpp(12): error C2143: syntax error : missing ';' before '}'
1>Network.cpp(15): error C2143: syntax error : missing ';' before '{'
1>Network.cpp(16): error C2653: 'Client' : is not a class or namespace name
1>Network.cpp(17): error C2653: 'Client' : is not a class or namespace name
1>Network.cpp(18): error C2143: syntax error : missing ';' before '}'
1>Network.cpp(21): error C2143: syntax error : missing ';' before '{'
1>Network.cpp(23): error C2143: syntax error : missing ';' before '{'
1>Network.cpp(26): error C2143: syntax error : missing ';' before '}'
1>Network.cpp(27): error C2143: syntax error : missing ';' before '}'
1>Network.cpp(30): error C2143: syntax error : missing ';' before '{'
1>Network.cpp(31): error C2355: 'this' : can only be referenced inside non-static member functions
1>Network.cpp(31): error C2227: left of '->rbuffer' must point to class/struct/union/generic type
1>Network.cpp(31): error C2065: 'cli' : undeclared identifier
1>Network.cpp(31): error C2143: syntax error : missing ',' before ')'
1>Network.cpp(32): error C2143: syntax error : missing ';' before '}'
1>Network.cpp(35): error C2065: 'Client' : undeclared identifier
1>Network.cpp(35): error C2065: 'cli' : undeclared identifier
1>Network.cpp(35): error C2143: syntax error : missing ',' before ')'
1>Network.cpp(36): error C2143: syntax error : missing ';' before '{'
1>Network.cpp(38): error C2355: 'this' : can only be referenced inside non-static member functions
1>Network.cpp(38): error C2227: left of '->msg' must point to class/struct/union/generic type
1>Network.cpp(38): error C2355: 'this' : can only be referenced inside non-static member functions
1>Network.cpp(38): error C2227: left of '->msg' must point to class/struct/union/generic type
1>Network.cpp(38): error C2228: left of '.size' must have class/struct/union
1>Network.cpp(38): error C2065: 'cli' : undeclared identifier
1>Network.cpp(38): error C2143: syntax error : missing ',' before ')'
1>Network.cpp(39): error C2143: syntax error : missing ';' before '}'
1>Network.cpp(42): error C2143: syntax error : missing ';' before '{'
1>Network.cpp(43): error C2355: 'this' : can only be referenced inside non-static member functions
1>Network.cpp(43): error C2227: left of '->rbuffer' must point to class/struct/union/generic type
1>Network.cpp(43): error C2228: left of '.size' must have class/struct/union
1>Network.cpp(43): error C2143: syntax error : missing ',' before ')'
1>Network.cpp(44): error C2143: syntax error : missing ';' before '}'
1>Network.cpp(47): error C2143: syntax error : missing ';' before '{'
1>Network.cpp(49): error C2143: syntax error : missing ';' before '}'
1>Network.cpp(52): error C2143: syntax error : missing ';' before '{'
1>Network.cpp(54): error C2143: syntax error : missing ';' before '}'
1>Network.cpp(55): error C2143: syntax error : missing ';' before '}'
1>Network.cpp(55): fatal error C1004: unexpected end-of-file found
Server.cpp
Client.h(10): error C2653: 'Network' : is not a class or namespace name
Client.h(10): error C2146: syntax error : missing ';' before identifier 'connection'
Client.h(10): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
Client.h(10): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
Client.h(13): error C2653: 'Network' : is not a class or namespace name
Client.h(13): error C2653: 'Network' : is not a class or namespace name
Client.h(13): error C2460: 'Client::ptr' : uses 'Client', which is being defined
Client.h(8) : see declaration of 'Client'
1>Server.cpp(22): error C2664: 'Client::Client(const Client &)' : cannot convert parameter 1 from 'Network::ptr' to 'const Client &'
Reason: cannot convert from 'Network::ptr' to 'const Client'
No user-defined-conversion operator available that can perform this conversion, or the operator cannot be called
After so many hours of "googlings" and reflexion, i didn't found why i have these errors.
Anyone can help me plz ?
Mmm.. Maybe you have left them out but you failed to include the headers:
Edit That seems to obvious. If it's not that then
Edit 2 Note that these suggestions have been typed when full information about the include structure wasn't given. The problems has been resolved now, but these hints are good general troubleshooting advice whenever strange issues arise with the compiler not 'seeing' your declarations:
check precompiled header settings (disable them, e.g.)
check you header include guards (if they are incorrect, e.g.
#ifndef __NETWORK_H
#define __NETWORK_H
...
#endif // __NETWORK_H
in your Client.h...
check namespace issues
accidentally declared Network in a namespace
included Network.h from within a namespace { ... } block
check preprocessor issues (#defines wreaking havoc?)
Server.cpp
include "Network.h"
include "Server.h"
//....
Client.cpp
include "Network.h"
include "Server.h"
Network.cpp
include "Network.h"
And probably (form looking at the errors):
Client.h
include "Network.h"
too
In Network.h, do not include Client.h, but instead forward declare class Client.
all, I have created the following code:
struct Styles{
wstring styleVal;
wstring styleName;
};
set<Styles> vtrStyles1;//filled in somehow
set<Styles> vtrStyles2;//filled in somehow
set<Styles> vtrStyles3(vtrStyles1);
vtrStyles3.insert(vtrStyles2.begin(), vtrStyles2.end());
unCommon = vtrStyles1.size() + vtrStyles2.size() - vtrStyles3.size();
I have included set in stdafx.h, and using namespace std; but i got the following errors:
1>XMLDOMFromVCDlg.cpp(5377): error C2065: 'set' : undeclared identifier
1>XMLDOMFromVCDlg.cpp(5377): error C2275: 'Styles' : illegal use of this type as an expression
1> XMLDOMFromVCDlg.cpp(5344) : see declaration of 'Styles'
1>XMLDOMFromVCDlg.cpp(5377): error C2065: 'vtrStyles1' : undeclared identifier
1>XMLDOMFromVCDlg.cpp(5378): error C2065: 'set' : undeclared identifier
1>XMLDOMFromVCDlg.cpp(5378): error C2275: 'Styles' : illegal use of this type as an expression
1> XMLDOMFromVCDlg.cpp(5344) : see declaration of 'Styles'
1>XMLDOMFromVCDlg.cpp(5378): error C2065: 'vtrStyles2' : undeclared identifier
1>XMLDOMFromVCDlg.cpp(5497): error C2065: 'vtrStyles1' : undeclared identifier
1>XMLDOMFromVCDlg.cpp(5497): error C2228: left of '.insert' must have class/struct/union
1> type is ''unknown-type''
1>XMLDOMFromVCDlg.cpp(5507): error C2065: 'vtrStyles1' : undeclared identifier
1>XMLDOMFromVCDlg.cpp(5507): error C2228: left of '.insert' must have class/struct/union
1> type is ''unknown-type''
1>XMLDOMFromVCDlg.cpp(5517): error C2065: 'vtrStyles1' : undeclared identifier
1>XMLDOMFromVCDlg.cpp(5517): error C2228: left of '.insert' must have class/struct/union
1> type is ''unknown-type''
1>XMLDOMFromVCDlg.cpp(5534): error C2065: 'vtrStyles1' : undeclared identifier
1>XMLDOMFromVCDlg.cpp(5534): error C2228: left of '.insert' must have class/struct/union
1> type is ''unknown-type''
1>XMLDOMFromVCDlg.cpp(5545): error C2065: 'vtrStyles1' : undeclared identifier
1>XMLDOMFromVCDlg.cpp(5545): error C2228: left of '.insert' must have class/struct/union
1> type is ''unknown-type''
1>XMLDOMFromVCDlg.cpp(5555): error C2065: 'vtrStyles1' : undeclared identifier
1>XMLDOMFromVCDlg.cpp(5555): error C2228: left of '.insert' must have class/struct/union
1> type is ''unknown-type''
1>XMLDOMFromVCDlg.cpp(5565): error C2065: 'vtrStyles1' : undeclared identifier
1>XMLDOMFromVCDlg.cpp(5565): error C2228: left of '.insert' must have class/struct/union
1> type is ''unknown-type''
1>XMLDOMFromVCDlg.cpp(5606): error C2065: 'vtrStyles2' : undeclared identifier
1>XMLDOMFromVCDlg.cpp(5606): error C2228: left of '.insert' must have class/struct/union
1> type is ''unknown-type''
1>XMLDOMFromVCDlg.cpp(5616): error C2065: 'vtrStyles2' : undeclared identifier
1>XMLDOMFromVCDlg.cpp(5616): error C2228: left of '.insert' must have class/struct/union
1> type is ''unknown-type''
1>XMLDOMFromVCDlg.cpp(5626): error C2065: 'vtrStyles2' : undeclared identifier
1>XMLDOMFromVCDlg.cpp(5626): error C2228: left of '.insert' must have class/struct/union
1> type is ''unknown-type''
1>XMLDOMFromVCDlg.cpp(5643): error C2065: 'vtrStyles2' : undeclared identifier
1>XMLDOMFromVCDlg.cpp(5643): error C2228: left of '.insert' must have class/struct/union
1> type is ''unknown-type''
1>XMLDOMFromVCDlg.cpp(5654): error C2065: 'vtrStyles2' : undeclared identifier
1>XMLDOMFromVCDlg.cpp(5654): error C2228: left of '.insert' must have class/struct/union
1> type is ''unknown-type''
1>XMLDOMFromVCDlg.cpp(5664): error C2065: 'vtrStyles2' : undeclared identifier
1>XMLDOMFromVCDlg.cpp(5664): error C2228: left of '.insert' must have class/struct/union
1> type is ''unknown-type''
1>XMLDOMFromVCDlg.cpp(5674): error C2065: 'vtrStyles2' : undeclared identifier
1>XMLDOMFromVCDlg.cpp(5674): error C2228: left of '.insert' must have class/struct/union
1> type is ''unknown-type''
1>XMLDOMFromVCDlg.cpp(5704): error C2065: 'set' : undeclared identifier
1>XMLDOMFromVCDlg.cpp(5704): error C2275: 'Styles' : illegal use of this type as an expression
1> XMLDOMFromVCDlg.cpp(5344) : see declaration of 'Styles'
1>XMLDOMFromVCDlg.cpp(5704): error C2065: 'vtrStyles1' : undeclared identifier
1>XMLDOMFromVCDlg.cpp(5704): error C3861: 'vtrStyles3': identifier not found
1>XMLDOMFromVCDlg.cpp(5705): error C2065: 'vtrStyles3' : undeclared identifier
1>XMLDOMFromVCDlg.cpp(5705): error C2228: left of '.insert' must have class/struct/union
1> type is ''unknown-type''
1>XMLDOMFromVCDlg.cpp(5705): error C2065: 'vtrStyles2' : undeclared identifier
1>XMLDOMFromVCDlg.cpp(5705): error C2228: left of '.begin' must have class/struct/union
1> type is ''unknown-type''
1>XMLDOMFromVCDlg.cpp(5705): error C2065: 'vtrStyles2' : undeclared identifier
1>XMLDOMFromVCDlg.cpp(5705): error C2228: left of '.end' must have class/struct/union
1> type is ''unknown-type''
1>XMLDOMFromVCDlg.cpp(5706): error C2065: 'vtrStyles1' : undeclared identifier
1>XMLDOMFromVCDlg.cpp(5706): error C2228: left of '.size' must have class/struct/union
1> type is ''unknown-type''
1>XMLDOMFromVCDlg.cpp(5706): error C2065: 'vtrStyles2' : undeclared identifier
1>XMLDOMFromVCDlg.cpp(5706): error C2228: left of '.size' must have class/struct/union
1> type is ''unknown-type''
1>XMLDOMFromVCDlg.cpp(5706): error C2065: 'vtrStyles3' : undeclared identifier
1>XMLDOMFromVCDlg.cpp(5706): error C2228: left of '.size' must have class/struct/union
1> type is ''unknown-type''
1>XMLDOMFromVCDlg.cpp(5707): error C2065: 'vtrStyles3' : undeclared identifier
1>XMLDOMFromVCDlg.cpp(5707): error C2228: left of '.size' must have class/struct/union
1> type is ''unknown-type''
so whats going on? thx in advance.
cheers
daiyue
There's something you're not telling us. The following program (copy-pasted by parts from your posted code) compiles fine using Visual Studio 2008, provided that you define operator< for your Styles struct (see below).
#include <set>
#include <string>
using namespace std;
struct Styles {
wstring styleVal;
wstring styleName;
};
int main ( int, char ** )
{
set<Styles> vtrStyles1;
set<Styles> vtrStyles2;
set<Styles> vtrStyles3(vtrStyles1);
vtrStyles3.insert(vtrStyles2.begin(), vtrStyles2.end());
const size_t unCommon =
vtrStyles1.size() + vtrStyles2.size() - vtrStyles3.size();
}
The following definition seems OK to me, but it might not be what you have in mind. Insert this before main().
bool operator< ( const Styles& lhs, const Styles& rhs )
{
return (lhs.styleName < rhs.styleName);
}
If you can compile this program, then your problem lies elsewhere.
You need to either use std::set or using std::set or using namespace std.
Also, make sure
#include <set>
in either stdafx.h or in your code.
Assuming you've edited stdafx.h to #include <set> and added using namespace std, did you hit Ctrl+F7 to just compile XMLDOMFromVCDlg.cpp? If so, you need to recompile stdafx.cpp first to regenerate the precompiled header.
I have tried to implement Stack Overflow question C++ Data Member Alignment and Array Packing. Here is the code:
#include <stdio.h>
#include <stddef.h>
typedef struct {
unsigned char a;
unsigned char b;
unsigned char c;
}foo;
typedef struct{
unsigned short i;
unsigned char a;
unsigned char b;
unsigned char c;
} Bar;
typedef struct {foo f[5];} f_b;
typedef struct {Bar[5];} b_f;
#define ALIGNMENT_OF(t) offsetof( struct { char x; t test; }, test )
int main(void){
printf("Foo:: Size: %d; Alignment: %d\n", sizeof(foo), ALIGNMENT_OF(foo));
printf("Bar:: Size: %d; Alignment: %d\n", sizeof(Bar), ALIGNMENT_OF(Bar));
printf("F_B:: Size: %d; Alignment: %d\n", sizeof(f_b), ALIGNMENT_OF(f_B));
printf("B_F:: Size: %d; Alignment: %d\n", sizeof(b_f), ALIGNMENT_OF(b_f));
return 0;
}
But here are the mistakes:
1>c:\users\david\documents\visual studio 2010\projects\data_packing\data_packing.cpp(16): error C2059: syntax error : '['
1>c:\users\david\documents\visual studio 2010\projects\data_packing\data_packing.cpp(16): error C2238: unexpected token(s) preceding ';'
1>c:\users\david\documents\visual studio 2010\projects\data_packing\data_packing.cpp(19): error C2332: 'struct' : missing tag name
1>c:\users\david\documents\visual studio 2010\projects\data_packing\data_packing.cpp(19): error C2143: syntax error : missing ')' before '{'
1>c:\users\david\documents\visual studio 2010\projects\data_packing\data_packing.cpp(19): error C2143: syntax error : missing ')' before '{'
1>c:\users\david\documents\visual studio 2010\projects\data_packing\data_packing.cpp(19): error C2059: syntax error : ')'
1>c:\users\david\documents\visual studio 2010\projects\data_packing\data_packing.cpp(19): error C2143: syntax error : missing '(' before ')'
1>c:\users\david\documents\visual studio 2010\projects\data_packing\data_packing.cpp(19): error C2143: syntax error : missing ')' before '{'
1>c:\users\david\documents\visual studio 2010\projects\data_packing\data_packing.cpp(19): error C2143: syntax error : missing ')' before '{'
1>c:\users\david\documents\visual studio 2010\projects\data_packing\data_packing.cpp(19): error C2143: syntax error : missing ')' before '{'
1>c:\users\david\documents\visual studio 2010\projects\data_packing\data_packing.cpp(19): error C2143: syntax error : missing ';' before '{'
1>c:\users\david\documents\visual studio 2010\projects\data_packing\data_packing.cpp(19): error C2059: syntax error : ')'
1>c:\users\david\documents\visual studio 2010\projects\data_packing\data_packing.cpp(19): error C2059: syntax error : ')'
1>c:\users\david\documents\visual studio 2010\projects\data_packing\data_packing.cpp(19): error C2227: left of '->test' must point to class/struct/union/generic type
1> type is 'int'
1>c:\users\david\documents\visual studio 2010\projects\data_packing\data_packing.cpp(19): error C2059: syntax error : ')'
1>c:\users\david\documents\visual studio 2010\projects\data_packing\data_packing.cpp(19): error C2059: syntax error : ')'
1>c:\users\david\documents\visual studio 2010\projects\data_packing\data_packing.cpp(19): error C2059: syntax error : ')'
1>c:\users\david\documents\visual studio 2010\projects\data_packing\data_packing.cpp(20): error C2332: 'struct' : missing tag name
1>c:\users\david\documents\visual studio 2010\projects\data_packing\data_packing.cpp(20): error C2143: syntax error : missing ')' before '{'
1>c:\users\david\documents\visual studio 2010\projects\data_packing\data_packing.cpp(20): error C2143: syntax error : missing ')' before '{'
1>c:\users\david\documents\visual studio 2010\projects\data_packing\data_packing.cpp(20): error C2059: syntax error : ')'
1>c:\users\david\documents\visual studio 2010\projects\data_packing\data_packing.cpp(20): error C2143: syntax error : missing '(' before ')'
1>c:\users\david\documents\visual studio 2010\projects\data_packing\data_packing.cpp(20): error C2143: syntax error : missing ')' before '{'
1>c:\users\david\documents\visual studio 2010\projects\data_packing\data_packing.cpp(20): error C2143: syntax error : missing ')' before '{'
1>c:\users\david\documents\visual studio 2010\projects\data_packing\data_packing.cpp(20): error C2143: syntax error : missing ')' before '{'
1>c:\users\david\documents\visual studio 2010\projects\data_packing\data_packing.cpp(20): error C2143: syntax error : missing ';' before '{'
1>c:\users\david\documents\visual studio 2010\projects\data_packing\data_packing.cpp(20): error C2059: syntax error : ')'
1>c:\users\david\documents\visual studio 2010\projects\data_packing\data_packing.cpp(20): error C2059: syntax error : ')'
1>c:\users\david\documents\visual studio 2010\projects\data_packing\data_packing.cpp(20): error C2227: left of '->test' must point to class/struct/union/generic type
1> type is 'int'
1>c:\users\david\documents\visual studio 2010\projects\data_packing\data_packing.cpp(20): error C2059: syntax error : ')'
1>c:\users\david\documents\visual studio 2010\projects\data_packing\data_packing.cpp(20): error C2059: syntax error : ')'
1>c:\users\david\documents\visual studio 2010\projects\data_packing\data_packing.cpp(20): error C2059: syntax error : ')'
1>c:\users\david\documents\visual studio 2010\projects\data_packing\data_packing.cpp(21): error C2332: 'struct' : missing tag name
1>c:\users\david\documents\visual studio 2010\projects\data_packing\data_packing.cpp(21): error C2143: syntax error : missing ')' before '{'
1>c:\users\david\documents\visual studio 2010\projects\data_packing\data_packing.cpp(21): error C2143: syntax error : missing ')' before '{'
1>c:\users\david\documents\visual studio 2010\projects\data_packing\data_packing.cpp(21): error C2059: syntax error : ')'
1>c:\users\david\documents\visual studio 2010\projects\data_packing\data_packing.cpp(21): error C2143: syntax error : missing '(' before ')'
1>c:\users\david\documents\visual studio 2010\projects\data_packing\data_packing.cpp(21): error C2143: syntax error : missing ')' before '{'
1>c:\users\david\documents\visual studio 2010\projects\data_packing\data_packing.cpp(21): error C2143: syntax error : missing ')' before '{'
1>c:\users\david\documents\visual studio 2010\projects\data_packing\data_packing.cpp(21): error C2143: syntax error : missing ')' before '{'
1>c:\users\david\documents\visual studio 2010\projects\data_packing\data_packing.cpp(21): error C2143: syntax error : missing ';' before '{'
1>c:\users\david\documents\visual studio 2010\projects\data_packing\data_packing.cpp(21): error C2065: 'f_B' : undeclared identifier
1>c:\users\david\documents\visual studio 2010\projects\data_packing\data_packing.cpp(21): error C2146: syntax error : missing ';' before identifier 'test'
1>c:\users\david\documents\visual studio 2010\projects\data_packing\data_packing.cpp(21): error C2059: syntax error : ')'
1>c:\users\david\documents\visual studio 2010\projects\data_packing\data_packing.cpp(21): error C2059: syntax error : ')'
1>c:\users\david\documents\visual studio 2010\projects\data_packing\data_packing.cpp(21): error C2227: left of '->test' must point to class/struct/union/generic type
1> type is 'int'
1>c:\users\david\documents\visual studio 2010\projects\data_packing\data_packing.cpp(21): error C2059: syntax error : ')'
1>c:\users\david\documents\visual studio 2010\projects\data_packing\data_packing.cpp(21): error C2059: syntax error : ')'
1>c:\users\david\documents\visual studio 2010\projects\data_packing\data_packing.cpp(21): error C2059: syntax error : ')'
1>c:\users\david\documents\visual studio 2010\projects\data_packing\data_packing.cpp(22): error C2332: 'struct' : missing tag name
1>c:\users\david\documents\visual studio 2010\projects\data_packing\data_packing.cpp(22): error C2143: syntax error : missing ')' before '{'
1>c:\users\david\documents\visual studio 2010\projects\data_packing\data_packing.cpp(22): error C2143: syntax error : missing ')' before '{'
1>c:\users\david\documents\visual studio 2010\projects\data_packing\data_packing.cpp(22): error C2059: syntax error : ')'
1>c:\users\david\documents\visual studio 2010\projects\data_packing\data_packing.cpp(22): error C2143: syntax error : missing '(' before ')'
1>c:\users\david\documents\visual studio 2010\projects\data_packing\data_packing.cpp(22): error C2143: syntax error : missing ')' before '{'
1>c:\users\david\documents\visual studio 2010\projects\data_packing\data_packing.cpp(22): error C2143: syntax error : missing ')' before '{'
1>c:\users\david\documents\visual studio 2010\projects\data_packing\data_packing.cpp(22): error C2143: syntax error : missing ')' before '{'
1>c:\users\david\documents\visual studio 2010\projects\data_packing\data_packing.cpp(22): error C2143: syntax error : missing ';' before '{'
1>c:\users\david\documents\visual studio 2010\projects\data_packing\data_packing.cpp(22): error C2059: syntax error : ')'
1>c:\users\david\documents\visual studio 2010\projects\data_packing\data_packing.cpp(22): error C2059: syntax error : ')'
1>c:\users\david\documents\visual studio 2010\projects\data_packing\data_packing.cpp(22): error C2227: left of '->test' must point to class/struct/union/generic type
1> type is 'int'
1>c:\users\david\documents\visual studio 2010\projects\data_packing\data_packing.cpp(22): error C2059: syntax error : ')'
1>c:\users\david\documents\visual studio 2010\projects\data_packing\data_packing.cpp(22): error C2059: syntax error : ')'
1>c:\users\david\documents\visual studio 2010\projects\data_packing\data_packing.cpp(22): error C2059: syntax error : ')'
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
But in code it does not show me a red line which indicates an error. How do I fix this problem?
See where it says \data_packing.cpp(16):? That 16 in parentheses is a line number.
In the struct b_f, you created an array of Bar without a name. Also, in C++, you don't need all that typedef stuff.
For starters
Bar[5]
is not valid code. It should be something like
Bar f[5]
Furthermore, that macro doesn't make sense. You might try this instead:
template< class T >
struct testStruct{ char x; T test; };
#define ALIGNMENT_OF(t) offsetof( testStruct< t >, test )
And finally there's a typo:
ALIGNMENT_OF(f_B) //should be f_b
The pragma pack and pop might be helpful. The example below will align each member on one byte boundaries. In VS this can also be set on a project level by changing the project setting C++/CodeGeneration/StructMemberAlignment.
#pragma pack(push, 1)
struct test {
int a;
char b[3];
double c;
};
#pragma pack(pop)