I'm just beginning to write code with C++, and I got stuck when I want to add reference to class from other project from the same solutions.
my Main code located at :
InventoryAppDLL (contains code to access Sql Database)
class : dbConnection.h
Code:
ref class dbConnection
{
public:
dbConnection();
void SetCommandText(String ^command,bool ^commandText);
int ExecuteScalar();
DataSet^ ExecuteDataSet();
DataTable^ ExecuteDataTable();
protected:
~dbConnection();
private:
DbConnection ^conn;
DbCommand ^cmd;
ConnectionStringSettings ^settings;
DbProviderFactory ^fac;
};
after i build the main project (InventoryAppDLL), it was success and contains no errors.
but after I include the header into another project (InventoryAppService),and then I build it, it contains error :
error C2143: syntax error : missing ';' before '^'
when I reference to the error, I've got ConnectionStringSettings missing library on dbConnectionClass (InventoryAppDLL).
private:
DbConnection ^conn;
DbCommand ^cmd;
ConnectionStringSettings ^settings; // <---
DbProviderFactory ^fac;
};
I think you don't even need to include the header file. Since you have already added a reference from the consuming project to the project containing this class, the consuming project can read the metadata from the DLL project and you can simply say:
auto x = ref new dbConnection();
Related
I have two projects in my solution:
1. Project1, containing camera code which captures image frames
2. Project2, which takes input image and does processing on it. I would like to share/provide the image generated in project1 to the project2. I am trying to use Project references to share data between projects.
I created a class(with namespace) containing the required data members(to be shared) and member functions(populating the data members) in Project1. I am not able to use this class in Project2 despite adding Project Reference in Project2.
Project1:
namespace TheImagingSource
{
class Images {
public:
UINT8 input_image1[IMAGE_SIZE];
UINT8 input_image2[IMAGE_SIZE];
void upload_image(Mat);
} TIS;
void Images::upload_image(Mat m)
{
memcpy(input_image1, m.data, IMAGE_SIZE);
memcpy(input_image2, m.data, IMAGE_SIZE);
}
}
The 'using Project1' statement in Project2 gives error: identifier 'Project1' is undefined.
I am defining a new interface and a class that implements it. I have added my class(XXX) and interface(IXXX) in idl file (I generated two uuids). My interface has two simple methods. I have implemented them( files XXX.h and XXX.cpp). I included the following line in InprocServer.cpp.
UNKNOWN_OBJECT(XXX)
I am getting the following error:
Error C2259 'XXX': cannot instantiate abstract class (compiling source file InprocServer.cpp)
clicking on error takes me to the following line in
Unknown.h
try
{
**p = new T(pUnkOuter); // refcount is already 1**
if (!p)
return E_OUTOFMEMORY;
}
How do I know which method is not implemented?
Look in the output window (View->Output)rather than the error list and any unimplemented members will be part of the diagnostic.
This works so long as you have the setting in Tools->Options, Projects and Solutions->Build and Run for MSBuild verbosity set to at least 'Minimal', I'm not sure about 'Quiet'.
I am working on some simulation software, written in C++. Currently, when trying to build my code, I get 9 compile errors, all complaining about the three lines of code that I've just added. Those lines are the declarations in PublisherModule.h:
class PublisherModule :
public s::Module,
public s::Singleton<PublisherModule>,
public s::Interface,
public s::htmlPage{
public:
...
Types::ModeRecord;
ModeRecord modeData;
ModeRecord *modeDataPtr;
...
};
The reason for adding these declarations into the PublisherModule.h was so that I could add the following code into the publish() function of the PublisherModule.cpp file:
Types::ModeRecord ModeData;
Types::ModeStatusRecord *ModeDataPtr = &ModeData;
DataStore->getModeData(*ModeDataPtr);
The publish() function now looks like this:
void PublisherModule::publishData(void){
...
Types::ModeRecord ModeData;
Types::ModeStatusRecord *ModeDataPtr = &ModeData;
DataStore->getModeData(*ModeDataPtr);
...
}
The errors that the compiler is giving me are:
error C2653: 'Types': is not a class or namespace name
error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
error C2146: syntax error : missing ';' before identifier 'ModeData'
error C2143: syntax error : missing ';' before '*'
I get error C4430 4 times in total, and the other errors all once each. They are all complaining about the lines that I added into the .h file. Having Google'd the first error, and come across this answer on SO: Compiler error C2653: not a class or namespace name , it would appear that the cause is a circular dependency in the header files...
But that is not happening here as far as I can tell... Are there any other reasons why I might get this compile error, and what's preventing my code from building?
The message displayed when I hover my cursor over the first line that I've added in the .h file, Types::ModeRecord is:
Error: a class-qualified name is required
Here is an abbreviated version of the code you posted, with my observation:
class PublisherModule [... bunch of base classes...]
{
public:
Types::ModeRecord;
};
What do you think this line does??
Types::ModeRecord;
It is not of the form [TypeName] [VariableName]; (eg int i;)
It does not look like a method prototype (eg void foo(int i);)
It is not a typedef.
It doesn't look like any normal C++.
What do you think it is doing?
I have a struct that is declared in a C++ header file with the line:
struct AII_Common_Export message{
...
};
I am then trying to create an instance of that struct in a C++ source file, so that I can set/ use some of the attributes stored in the struct:
message data;
However, when I compile my code, I get an "undeclared identifier" error on this line... I have included the header file in the source file, so I don't understand why I am getting this error- can someone explain it to me?
I also tried creating the instance of it with:
AII_Common_Export message data;
But then got the compile error: "syntax error: missing ';' before identifier 'data'.
Any ideas how I can fix this, so that I can create an instance of the struct?
EDIT
I have just found the AII_Common_Export definition- it is defined with:
# define AII_Common_Export ACE_Proper_Import_Flag
and the ACE_Proper_Import_Flag is defined with:
#define ACE_Proper_Import_Flag __declspec (dllimport)
These two definitions are in separate header files.
Just do.
struct message{
...
};
message data;
see http://www.cplusplus.com/doc/tutorial/structures/
I'm trying to generate a class diagram, using reverse engineering, but the following is happening:
There was an error parsing C:\Documents and Settings\Meus documentos\EA_Documentos\Modelos\Environment\class\Factory.h on line 11. Unexpected symbol: ISIMFactory
You may need to define a language macro.
There was an error parsing C:\Documents and Settings\Meus documentos\EA_Documentos\Modelos\Environment\class\Model.h on line 99. Unexpected symbol: ISIMModel
You may need to define a language macro.
There are many more of these.
This is the corresponding code in CSIMEnvironmentModel.h
class SIMMDLENVv01_EXPORT CSIMEnvironmentModel // line 99
: public ISIMModel
, public ISIMEventSource
, public ISIMScheduledModel
, public ISIMExecut
, public ISIMPublisher
{
public:
CSIMEnvironmentModel(const std::string &a_modelType);
virtual ~CSIMEnvironmentModel(void);
and CSIMEnvFactory.h
class SIMMDLENVv01_EXPORT CSIMEnvFactory // line 11
: public ISIMFactory
{
public:
CSIMEnvFactory();
virtual ~CSIMEnvFactory(void);
std::vector<ISIMModel*> InstanceModel(const std::string &a_modelType, const std::string &a_conf);
};
What's the reason for this error message?
Your code contains usage of a macro definition (SIMMDLENVv01_EXPORT) that isn't part of EA's standard macro definitions (there's whole a lot of them covering ATL and MFC mostly).
You'll need to add additional ones under 'Settings->Language Macros' (as the hint in the error message suggests).
NOTE
Use the syntax MACRO() when declaring macros that were #defined to receive any number of arguments.
If you're trying to reverse engineer framework libraries like Qt or alike, you'll need to set many of these that you're able to reverse engineer the code without getting errors.
May be you should think of a different strategy to reference these types and classes in your model then.
Another workaround might be to solely preprocess all the code you want to import first, and import from the preprocessed results.