I trying to create a DLL with this code but in line 7, I am getting this two errors "E0169 - expected a declaration" and "C2447 - '{' : missing function header (old-style formal list?)"
Asked
Active
Viewed 210 times
0
-
2Typo? `class GDT_dll; {` -> `class GDT_dll {`? `public void main();` -> `public: void main();`? Oh, and your `cout`s, and `cin`s are not in a function scope, as they must be. Additional recommendation: learn C++ from a [good C++ book](https://stackoverflow.com/questions/388242/the-definitive-c-book-guide-and-list), instead of coding randomly. – Algirdas Preidžius Apr 16 '21 at 09:39
-
1You need to study the fundamentals of C++ grammar. (And it's too early for you to start thinking about creating a DLL. You need to have learned the basics - and more - first.) – molbdnilo Apr 16 '21 at 10:01
2 Answers
0
You left a ; after your class name.
Also you should put : after public for your function definition.
Also, if you try to define a function within your class, the syntax should be as follows :
class className
{
int attribute;
public : void foo(){
cout << "Value of attribute is " << attribute << endl;
}
};
That is to say without a ; and with the { after the parenthesis.
I suggest you take a look at this link to understand how to properly create a class.

Zekovski
- 301
- 1
- 10
0
1, When you create a class, you couldn't need the ;
after the GDT_dll
.
class GDT_dll
{
……
}
2, You need the :
after public
.
3, You couldn't name the function to "main", because the main function has a special meaning.
4, Finally, you need a ";"after the last "}"
Here is the code:
#include"pch.h"
#include <stdio.h>
#include <iostream>
#include <string>
#include <conio.h>
using namespace std;
class GDT_dll
{
public : void foo()
{
string name, firstName;
int birthDate, birthMonth, birthYear;
cout << "Enter Name: ";
cin >> name;
cout << "Enter First Name: ";
cin >> firstName;
cout << "Enter Birth Date: ";
cin >> birthDate;
cout << "Enter Birth Month: ";
cin >> birthMonth;
cout << "Enter Birth Year: ";
cin >> birthYear;
}
};
If you want to create a DLL, I suggest you could refer to the Doc: Walkthrough: Create and use your own Dynamic Link Library

Jeaninez - MSFT
- 3,210
- 1
- 5
- 20
-
@A.MUSTAQ AHMED Have you got any updates? If your case has been solved, please help to mark answers. If not, just feel free to contact us. Your understanding and cooperation will be grateful. – Jeaninez - MSFT Apr 28 '21 at 02:57