I created simple code in MVS2010 but it doesn’t work.
There is just a class with header file and main.
Could you tell me what is wrong?
Main:
#include <iostream>
#include "Developer.h"
int main() {
Developer xx("asd", "sfdasdf", "asdsa");
std::cout << xx.Dev_ID;
char c;
std::cin >> c;
return 0;
}
Header:
class Developer {
public:
char * Dev_ID;
char * Dev_Name;
char * ApplicationType;
char * Name_Application;
public:
Developer(char * name, char * appType, char * appName);
void create();
void edit();
void remove();
};
Class:
#include "Developer.h"
Developer::Developer(char * name, char * appType, char * appName){}
void Developer::create(){}
void Developer::edit(){}
void Developer::remove(){}
Of course it does. Your constructor doesn’t fill in any of the member variables. So
xx.Dev_IDis undefined; it contains random garbage. When you attempt tostd::coutrandom garbage, the program rightly crashes.You probably intend to initialize
Dev_IDto some value. You need to do that in the constructor. That’s what the constructor is for: initializing member variables.As Chethan stated, you need to look through some basic C++ books.