I
I
IlyaKryazh2015-09-06 18:01:14
Programming
IlyaKryazh, 2015-09-06 18:01:14

How to divide a project into elements in Vusial studio and then make them one whole?

In general, I need to implement a large project, and it’s inconvenient to do everything about one element (I’m afraid to get confused) and I would like to somehow separate the project. For example, something in one element would be main and in another function.

Answer the question

In order to leave comments, you need to log in

3 answer(s)
A
Alexander Movchan, 2015-09-06
@IlyaKryazh

Do you mean to split the project into several files?
You will need to create two files for each module: a header file (with declarations) and the actual implementation (definition) file. Declaration files have the extension .h .H .hpp and so on.
main.cpp: definition of the main function.

// Следующая строка при компиляции будет заменена на содержимое файла helloworld.h
#include "helloworld.h"

int main(int argc, char** argv)
{
    helloworld(); // Вызываем функцию определённую в другом файле.
    return 0;
}

helloworld.h: declaration of the helloworld function
// Следующая конструкция называется include guard.
// Благодаря ней вы не сможете вставить содержимое этого файла дважды,
// что поможет вам избежать ошибок переопределения.
#ifndef HELLOWORLD_H 
#define HELLOWORLD_H

// Объявление функции.
// Если функция объявлена но не определена в данном файле,
// компилятор будет искать её реализацию в других файлах.
void helloworld();

#endif

helloworld.cpp
// Снова вставляем содержимое файла helloworld.h
#include "helloworld.h"

#include <iostream>

// Определяем функцию.
void helloworld()
{
    std::cout << "Hello, world!";
}

T
TyzhSysAdmin, 2015-09-06
@POS_troi

Mmmm .. Of course, I could be wrong, but it seems to be called OOP :)

M
MrDywar Pichugin, 2015-09-06
@Dywar

Object-Oriented Programming (C# and Vi...
Recording of a seminar on the topic "What is OOP and what is it with ...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question