C++/CLI metadata error when adding methods to children class - c++-cli

I have a weird problem and can't figure out what's this about.
I have a child class that's .h file is created like this:
#pragma once
#include "stdafx.h"
#include "Osoba.h"
#include "Lekarz.h"
ref class Pacjent :
public Osoba
{
public:
Pacjent(String ^ imie, String ^ nazwisko, String ^ telefon, String ^ pesel) :
Osoba(imie, nazwisko, telefon) {
}
bool appointVisit(DateTime^ date, Lekarz^ lekarz);
protected:
String ^ pesel;
private:
int getGender();
};
It works exactly as expected when there's no appointVisit method. After adding it I started receiving error LNK2022 saying that metadata in duplicated types.
It works just fine in classes that don't inherit. In inherited classes I cannot get it working properly. What am I doing wrong guys?

Related

How to use other class enum properties in Qml

Given is a class ClassA which contains an enum:
class ClassA : public QObject
{
Q_OBJECT
QML_ELEMENT
public:
enum EnumClassA {
};
Q_ENUM(EnumClassA)
};
A second class has a property of ClassA::EnumClassA:
#include <ClassA.h>
class ClassB : public QObject
{
Q_OBJECT
QML_ELEMENT
Q_PROPERTY(ClassA::EnumClassA value READ ...)
public:
};
This works in Qml (meaning the property value can be used in Qml), but when using qmlint/qmlsc compiler the following message is shown:
error: Could not compile binding for value: Cannot generate efficient code for content pointer of non-QVariant wrapper type double of ClassB::value with type ClassA::EnumClassA
A dirty fix could be this:
// replace "Q_PROPERTY(ClassA::EnumClassA value READ ...)" with:
Q_PROPERTY(int value READ ...)
but it would be much nicer to keep the type in the property.
Is it possible to modify the enum so that it can be compiled?
Regards,

Static Object of a class in another class in aggregation relationship C++

I have two classes first class contains the object of another class as static but C++ doesnot allow me to do this and gives me some error.
source.cpp
#include"control.h"
int main()
{
Controller cnt;
cnt.tempcont();
return 0;
}
control.h
#include"recorder.h"
class Controller
{
public:
static recorder rec;
void tempcont();
};
recorder Controller::rec;
control.cpp
#include"control.h"
void Controller::tempcont()
{
rec.temprec();
}
recorder.h
#include<iostream>
using namespace std;
class recorder
{
public:
int a;
void temprec();
};
recorder.cpp
#include"recorder.h"
void recorder::temprec()
{
cout << "temp rec called";
}
I am getting the following errors and i have no idea why these errors are comming..
Error LNK1169 one or more multiply defined symbols found
Error LNK2005 "public: static class recorder Controller::rec" (?rec#Controller##2Vrecorder##A) already defined in control.obj
You define the variable Controller::rec in the header file. That means the variable will be defined in every translation unit where that header file have been included. It should only be defined in one single translation unit.
This is very easy to do: Just move the definition to a single source file.

ERROR, vertex_descriptor': is not a member of 'StitchPolyhedron', if StitchPolyhedron is inherited from Polyhedron_3

There is an error if class inherits from Polyhedron_3 and used in stitch_borders, but if I use the Polyhedron_3 directly in stitch_borders there is no error.
typedef CGAL::Exact_predicates_inexact_constructions_kernel K;
class StitchPolyhedron : public CGAL::Polyhedron_3<K>
{
public:
StitchPolyhedron() {}
virtual ~StitchPolyhedron() {}
};
StitchPolyhedron mesh;
CGAL::Polygon_mesh_processing::stitch_borders(mesh);
Code above gives an error
vertex_descriptor': is not a member of 'StitchPolyhedron'
typedef CGAL::Exact_predicates_inexact_constructions_kernel K;
typedef CGAL::Polyhedron_3<K> StitchPolyhedron;
StitchPolyhedron mesh;
CGAL::Polygon_mesh_processing::stitch_borders(mesh);
Code above compiles fine.
Can anyone point me what is the issue here.
Your inherited class must be a model of FaceListGraph. Usually adding in a boost namespace the following partial specialization should be sufficient:
namespace boost {
struct boost::graph_traits<POLYHEDRON_TYPE>:
public boost::graph_traits<BASE_POLYHEDRON_TYPE>
{};
} // namespace boost
You might need to forward properties as well. Add in a boost namespace the following partial specialization:
namespace boost{
template <class Tag>
struct property_map<POLYHEDRON_TYPE, Tag> :
public property_map<BASE_POLYHEDRON_TYPE, Tag>
{};
} //namespace boost

Runtime exception when calling C++/CLI derived class

Edited by the OP 5 August 2014:
Much simplified code:
public ref class CXmlWriter : public System::Xml::XmlTextWriter
{
public:
CXmlWriter(System::String ^sFilename) : XmlTextWriter(sFilename, System::Text::Encoding::Unicode)
{
}
~CXmlWriter()
{
}
};
Call a function containing code that instantiates CXmlWriter (you don't have to execute that instantiation code) and you get the exception.
Comment out the destructor and you don't get the exception. Making the destructor virtual doesn't fix it.
End of edit
I am using Version 4 of the .NET framework.
I have C++/CLI classes CXmlWriter derived from System::Xml::XmlTextWriter and CMinMaxXmlWriter derived from CXmlWriter.
Implementation is pretty simple for both classes and everything compiles without error. However, when I try to instantiate CMinMaxXmlWriter at runtime I get a TypeLoadException with the error message:
Declaration referenced in a method implementation cannot be a final method
with a mention of CXmlWriter
This used to work without any problem in Version 2 of the framework.
Here's the header for CXmlWriter:
public ref class CXmlWriter : public System::Xml::XmlTextWriter
{
public:
CXmlWriter(System::String ^sFilename);
~CXmlWriter();
!CXmlWriter() {}
virtual bool Open();
virtual void Close() override;
virtual bool WriteValueAndAttribute(System::String ^sElementName, System::String ^sElementValue, System::String ^sAttrName, System::String ^sAttrValue);
virtual bool WriteValueAndAttribute(System::String ^sElementName, double dElementValue, System::String ^sAttrName, System::String ^sAttrValue);
protected:
bool m_bIsOpen;
};
CMinMaxXmlWriter is defined in a very similar way.
Please can someone explain why the exception occurs and what I should do to avoid it.

include different headers for cases

Is it possible to use for case 1 one header and for case 2 another?
Because when I use both headers in program I've got ambiguous symbol errors.
header 1(winapifunctions.h)
#include <Windows.h>
void CallWindowProc(String^ windowtitle)
{
};
header 2(classes.h)
using namespace System;
using namespace System::Collections::Generic;
public delegate void Super();
public ref class Event{};
public ref class MyException:public DivideByZeroException{};
public interface class IType{};
public interface class IVal{};
public ref class Writer abstract{};
public ref class Check: public Writer,public IType,public IVal
.....other classes
main program
#include "stdafx.h"
#include "classes.h"
#include "winapifunctions.h"
int main(array<System::String^>^ args)
{
//read x
switch(x){ case 1: {CallWindowProc("title");break;} case 2: { Check^ obj = gcnew Check();break;}
};
and error - IServiceProvider:ambiguous symbol
Short answer: No.
Long answer: includes are processed by the pre-processor, during compile time, while your case statements are processed during runtime. There's no way to make a compile-time thing to happen during runtime.
What are you trying to achieve exactly?
You can work around this problem using the following code:
// 1.cpp
case 1:
DoCase1();
break;
case 2:
DoCase2();
break;
// 2.cpp
#include <Windows.h>
void DoCase1()
{
// ...
}
// 3.cpp
#include <AnotherHeader.h>
void DoCase2()
{
// ...
}
If you would post more code and exact error messages, perhaps a better solution can be found.