C++ error C4430 int assumed - c++

I'm a newbie in C++ and have just a small header file in C++ with a simple struct in it.
PGNFinder.h:
#ifndef PGNFINDER_H
#define PGNFINDER_H
struct Field
{
int Order;
string Name;
//more variables but doesn't matter for now
};
#endif
This gives the next errors:
error C2146: syntax error : missing ';' before identifier 'Name'
error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
when I change it to:
struct Field
{
int Order;
std::string Name;
};
It gives a error in the .exe file and the .obj file
error LNK1120: 1 unresolved externals (in the .exe file)
error LNK2019: unresolved external symbol "int __cdecl Convert::stringToInt(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >)" (?stringToInt#Convert##YAHV?$basic_string#DU?$char_traits#D#std##V?$allocator#D#2##std###Z) referenced in function "private: void __thiscall CAN::calculateMessageLength(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >)" (?calculateMessageLength#CAN##AAEXV?$basic_string#DU?$char_traits#D#std##V?$allocator#D#2##std###Z)
and when I add
#include <string>
and change back to
string Name;
It gives the same errors as in the beginning.
So why can't the header file recognize the int and string?
Thanks for the help :)

In order to use string as type of a variable, you need to
include the header in which it is declared (#include <string>)
use a full qualified type such as std::string or by means of the using directory using namespace std; Note, however, that using is not recommended in header files (see "using namespace" in c++ headers)
If you only try one of these, it won't work.
However, your second error message seems to point to a linker problem.

Since I tend to use the comment function too often.
Your problem is a missing include, and when you included string.h you still forgot the std-namespace of the "string class".
So either use a using namespace std (for beginners best practice, since most stuff will be most likely std stuff)
or declare your string as std::string within your struct.

changing it to std::string clearly fixes the compiler error.
Then you have a linker error which is not related to that line of code. You appear to have a 'Convert' class with a missing implementation of a 'stringToInt' function.

Related

Linking boost::locale with Embarcadero Berlin 10.1

I've created a simple console application in Embarcadero Berlin 10.1, selected 32 bit clang compiler, and copied in some code from here in the boost docs.
Here is the full code
#pragma hdrstop
#pragma argsused
#ifdef _WIN32
#include <tchar.h>
#else
typedef char _TCHAR;
#define _tmain main
#endif
#include <stdio.h>
#include <boost/locale.hpp>
int _tmain(int argc, _TCHAR* argv[])
{
using namespace boost::locale;
using namespace std;
generator gen;
locale loc=gen("");
// Create system default locale
locale::global(loc);
// Make it system global
cout.imbue(loc);
// Set as default locale for output
cout <<format("Today {1,date} at {1,time} we had run our first localization example") % time(0)
<<endl;
cout<<"This is how we show numbers in this locale "<<as::number << 103.34 <<endl;
cout<<"This is how we show currency in this locale "<<as::currency << 103.34 <<endl;
cout<<"This is typical date in the locale "<<as::date << std::time(0) <<endl;
cout<<"This is typical time in the locale "<<as::time << std::time(0) <<endl;
cout<<"This is upper case "<<to_upper("Hello World!")<<endl;
cout<<"This is lower case "<<to_lower("Hello World!")<<endl;
cout<<"This is title case "<<to_title("Hello World!")<<endl;
cout<<"This is fold case "<<fold_case("Hello World!")<<endl;
return 0;
}
But I get some linker errors:
[ilink32 Error] Error: Unresolved external 'boost::system::generic_category()' referenced from C:\PROGRAM FILES (X86)\EMBARCADERO\STUDIO\18.0\LIB\WIN32C\RELEASE\LIBBOOST_LOCALE-BCB32C-MT-SD-1_55.LIB|generator
[ilink32 Error] Error: Unresolved external 'boost::system::system_category()' referenced from C:\PROGRAM FILES (X86)\EMBARCADERO\STUDIO\18.0\LIB\WIN32C\RELEASE\LIBBOOST_LOCALE-BCB32C-MT-SD-1_55.LIB|generator
[ilink32 Error] Error: Unresolved external 'boost::locale::impl_win::create_convert(std::locale&, boost::locale::impl_win::winlocale&, unsigned int)' referenced from C:\PROGRAM FILES (X86)\EMBARCADERO\STUDIO\18.0\LIB\WIN32C\RELEASE\LIBBOOST_LOCALE-BCB32C-MT-SD-1_55.LIB|win_backend
[ilink32 Error] Error: Unresolved external 'boost::locale::impl_win::create_collate(std::locale&, boost::locale::impl_win::winlocale&, unsigned int)' referenced from C:\PROGRAM FILES (X86)\EMBARCADERO\STUDIO\18.0\LIB\WIN32C\RELEASE\LIBBOOST_LOCALE-BCB32C-MT-SD-1_55.LIB|win_backend
[ilink32 Error] Error: Unresolved external 'boost::locale::impl_win::create_formatting(std::locale&, boost::locale::impl_win::winlocale&, unsigned int)' referenced from C:\PROGRAM FILES (X86)\EMBARCADERO\STUDIO\18.0\LIB\WIN32C\RELEASE\LIBBOOST_LOCALE-BCB32C-MT-SD-1_55.LIB|win_backend
[ilink32 Error] Error: Unresolved external 'boost::locale::impl_win::create_parsing(std::locale&, boost::locale::impl_win::winlocale&, unsigned int)' referenced from C:\PROGRAM FILES (X86)\EMBARCADERO\STUDIO\18.0\LIB\WIN32C\RELEASE\LIBBOOST_LOCALE-BCB32C-MT-SD-1_55.LIB|win_backend
The first two I can fix by manually adding libboost_locale-bcb32c-MT-SD-1_55.lib to the project, it's my understanding and experience with boost that it shouldn't really need manually linking, but I don't mind this. The last 4 however, I'm not sure about at all. It looks to be related to the locale backend (Is it not ICU with Embarcadero supplied boost?)
Does anyone have any advice?
Your problem is very interesting to me. So I created a new project and copied your code into it and sure enough the problem repeated itself.After doing some research the only way I was able to overcome this issue was by adding collate.cpp and converter.cpp and numeric.cpp located in $(BDSINCLUDE)\boost_1_55\libs\locale\src\win32 into my project.
I also had to add #pragma link "libboost_system-bcb32c-mt-sd-1_55.lib" into my source code before the main function.
Sam

A dll with a vector of vectors. in one of its classes methods

In my c++ program i'm trying to create a dll that houses the functionality of my a* algorithm.
I encounter a problem when trying to pass the map into it, I first tried to use a 2d array, but that limited my map sizes, so i'm now trying to use a vector in a vector and I keep hitting some odd snag.
In my dlls .h file:
namespace IInterface
{
class IInterface
{
public:
// Sets the map
static __declspec(dllexport) void setMap(int h, int w,vector<vector<byte>> &myarray);
private:
static vector<vector<byte>> mymap;
}
Finaly in the .cpp i have:
#include "IInterface.h"
#include <Windows.h>
#include <stdexcept>
#include <vector>
using namespace std;
namespace IInterface
{
void IInterface::setMap(int h, int w,vector<vector<byte>> &myarray)
{
mymap = myarray;
}
}
Im getting a few errors on compilation even tho the code looks fine to me.
error C2061: syntax error : identifier 'vector' c:\users\steven\documents\github\schooladvgdproject\game code\deathastardll\iinterface.h 7 1 DMAstarDLL
error C2143: syntax error : missing ';' before '<' c:\users\steven\documents\github\schooladvgdproject\game code\deathastardll\iinterface.h 21 1 DMAstarDLL
error C2238: unexpected token(s) preceding ';' c:\users\steven\documents\github\schooladvgdproject\game code\deathastardll\iinterface.h 21 1 DMAstarDLL
error C2511: 'void IInterface::IInterface::setMap(int,int,std::vector<_Ty> &)' : overloaded member function not found in 'IInterface::IInterface' c:\users\steven\documents\github\schooladvgdproject\game code\deathastardll\iinterface.cpp 13 1 DMAstarDLL
error C4430: missing type specifier - int assumed. Note: C++ does not support default-int c:\users\steven\documents\github\schooladvgdproject\game code\deathastardll\iinterface.h 21 1 DMAstarDLL
I looked at some samples, but there was really nothing that matched this scenario. I have a sneaking suspicion i'm forgetting something crucial, but I cant see it. Ideas on getting this to work?
your dlls.h does not include vector type - you should tell the compiler vector definition and include .
Tip: don't use using namespace std; in header file only in cpp. Instead of this use std::vector ...etc.
Secondly, be careful when your dll interface contains stl. This library differs as regards Release and Debug versions, so if you load Release dll in Debug program you could have problems.

Why am I getting this error ? "unresolved external symbol" [duplicate]

This question already has answers here:
What is an undefined reference/unresolved external symbol error and how do I fix it?
(39 answers)
Closed 9 years ago.
This is the error I have been getting the whole time and I've been trying to figure out how to fix it but have failed. I am asking if anyone can point me to the right direction.
WorldServer fatal error LNK1120: 2 unresolved externals
WorldServer error LNK2019: unresolved external symbol "public: class CItemElem * __thiscall CLinkedItemMgr::GetLinkedItem(unsigned long)" (?GetLinkedItem#CLinkedItemMgr##QAEPAVCItemElem##K#Z) referenced in function "private: void __thiscall CDPSrvr::OnLinkedItem(class CAr &,unsigned long,unsigned long,unsigned char *,unsigned long)" (?OnLinkedItem#CDPSrvr##AAEXAAVCAr##KKPAEK#Z)
WorldServer error LNK2019: unresolved external symbol "public: int __thiscall CLinkedItemMgr::AddLinkedItem(class CItemElem *)" (?AddLinkedItem#CLinkedItemMgr##QAEHPAVCItemElem###Z) referenced in function "private: void __thiscall CDPSrvr::OnLinkedItem(class CAr &,unsigned long,unsigned long,unsigned char *,unsigned long)" (?OnLinkedItem#CDPSrvr##AAEXAAVCAr##KKPAEK#Z)
This is the .h
#ifndef __ITEM_LINK__H
#define __ITEM_LINK__H
class CLinkedItemMgr
{
private:
CLinkedItemMgr(){ m_dwLinkedItemCount = 0;};
~CLinkedItemMgr(){};
DWORD m_dwLinkedItemCount;
public:
map<DWORD,CItemElem*> m_mapLinkedItems;
static CLinkedItemMgr *GetInstance()
{
static CLinkedItemMgr instance;
return &instance;
}
int AddLinkedItem(CItemElem *pItem);
CItemElem *GetLinkedItem(DWORD dwIndex);
};
#endif
this is the .cpp
#include "stdafx.h"
#include "ItemLink.h"
int CLinkedItemMgr::AddLinkedItem(CItemElem *pItem)
{
if(!pItem)
return 0;
m_mapLinkedItems.insert(make_pair<DWORD,CItemElem*>(++m_dwLinkedItemCount,pItem));
return m_dwLinkedItemCount;
}
CItemElem *CLinkedItemMgr::GetLinkedItem(DWORD dwIndex)
{
map<DWORD,CItemElem*>::iterator it = m_mapLinkedItems.find(dwIndex);
if(it == m_mapLinkedItems.end())
return FALSE;
return it->second;
}
Your problem is in the cpp here.
#ifdef __ITEM_LINK
#include "ItemLink.h"
#ifdef __ITEM_LINK means "only process the code below if __ITEM_LINK is defined"
And in your case, it is not defined. It only gets defined when "ItemLink.h" is included, and "ItemLink.h" only gets included if it's already defined. You've prevented either from happening first.
Remove the #ifdef line.
It looks like a linking problem.
The compiler knows your class has a function called GetLinkedItem but can't find any definition of that function anywhere. Are you linking properly when compiling your executable?
I bet stopping the compiler before linking doesn't trigger any error.
(e.g. g++ -c ItemLink.cpp).
i'm going to ask the help of someone who's accustomed to visual studio to elaborate more :D
anyway, compiling requires three major steps:
1) applying preprocessor directives, parsing the source code, looking for syntax errors and the like
2) creating an object file from source code (something half-way between source code and executable)
3) linking all the object files making up your project in one executable
your compiling chain fails at the third step.
the compiler expects a certain function to be defined in some .cpp (that has become an object file at step 2 of compiling chain) but can't find it anywhere.
and it can't find it because of that #ifdef in the .cpp file, which tells the preprocessor NOT TO INCLUDE your definitions, since __ITEM_LINK is not defined
i see you changed the .cpp in your question by the way

Compiling problems with wstring in c++

I need to refactor a .dll for a Zinc based Flash application.
After copy&paste a class from the master to the branch, I'm getting some strange compiling errors:
GameInfo.h(15): error C2146: syntax error : missing ';' before identifier 'm_wsVersion'
GameInfo.h(15): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
GameInfo.h(15): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
The addressed code:
// removed the comments
#include "stdafx.h"
#include <string.h>
class GameInfo {
public:
UINT m_uiGameId;
wstring m_wsVersion; // Line 15
UINT m_uiCheckSum;
wstring m_wsFilePath; // Same error report as on line 15
public:
static BOOL createFromFile(wstring path, GameInfo &target); // error "error C2061: syntax error : identifier 'wstring'" thrown
};
I use Visual Studio 2010 and in the IDE itself everything is okay, no syntactical errors or something like that. And as said I did not touch the code, headers seem fine.
Has anyone a clue what about this error?
Try using the string header, and qualifying the namespace:
#include <string>
class GameInfo {
....
std::wstring m_wsVersion;
};
#include <string> is the right standard include in C++ for string classes and use std::wstring.
I strongly recommend AGAINST using a using namespace std; inside one of your headers, as you would force anybody using the header to pull in the std stuff into the global namespace.

Trouble compiling a header file in VC++

I just reorganized the code for a project and now I'm getting errors I can't resolve. This header is included by a .cpp file trying to compile.
#include "WinMain.h"
#include "numDefs.h"
#include <bitset>
class Entity
{
public:
Entity();
virtual ~Entity();
virtual bitset<MAX_SPRITE_PIXELS> getBitMask();
virtual void getMapSection(float x, float y, int w, int h, bitset<MAX_SPRITE_PIXELS>* section);
};
I'm getting these compiler errors for the declaration of Entity::getBitMask():
error C2143: syntax error : missing ';' before '<'
error C2433: 'Entity::bitset' : 'virtual' not permitted on data declarations
error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
error C2238: unexpected token(s) preceding ';'
There are more similar errors for the next line as well. It seems like bitset isn't getting included but it clearly is? I can't figure out what's going wrong. WinMain.h includes windows.h, and numDefs.h includes nothing.
Using MS Visual C++ 2008.
Declare the bitset as std::bitset<MAX_SPRITE_PIXELS>.
The bitset template is defined in the std:: namespace, so you either need to reference it by it's full name std::bitset or add using namespace std; somewhere before the class declaration.
I think you need to say std::bitset.
Looks like an error in "numDefs.h"