I’m quite new to C++ and his syntax. I have programmed in C# before, but thought to give C++ a try.
I created a ClassLibrary in visual studio and want to add some classes to it. I know this is Managed C++.
But I can’t wrap my head around why I keep getting these errors:
Error C2062: type 'int' unexpected
Error C2143: syntax error: messing ; before '{'
Error C2447: '{' : missing function header (old-style formal list?)
This is my Header file:
// LibraryLib.h
#pragma once
#include <string>
using namespace System;
namespace LibraryLib {
public enum EntryType {Book, Newspaper};
public ref class Entry
{
public:
int id;
int year;
String ^ title;
EntryType type;
Entry(int Id, int Year, String ^ Title, EntryType Type);
};
}
This is my cpp file:
// This is the main DLL file.
#include "stdafx.h"
#include "LibraryLib.h"
namespace LibraryLib {
LibraryLib::Entry(int Id, int Year, String ^ Title, EntryType Type) // line of errors
{
id = Id;
year = Year;
title = Title;
type = Type;
}
}
The 3 errors are thrown on the line where I want to implement the constructor in the cpp file.
I hope some one can point me out what I’m doing wrong.
Thanks!
You aren’t qualifying the constructor right. You need another
Entry::in there: