当我在Code :: Blocks中具有来自同一组源文件的两个.cpp文件时,如何运行其中一个? [英] When I have two .cpp files from the same set of source files in Code::Blocks, how can I run one of them?

查看:565
本文介绍了当我在Code :: Blocks中具有来自同一组源文件的两个.cpp文件时,如何运行其中一个?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在一个项目的同一来源下,我有两个不同的 .cpp 文件(链接列表)。我尝试运行一个名为客户的链接列表文件,但仅运行另一个名为视频的文件。如何运行客户链接列表文件?

I have two different .cpp files (linked lists) under the same set of source of one project. I tried running one of the linked list files called "customer", but it's only running the other one called "video". How can I run the "customer" linked list file?

我的 customer.cpp 文件处于活动状态,但仍处于活动状态

My customer.cpp file is active but it's still running the program for the "video" linked list file.

基本上,我试图将两个单独的客户列表和另一个单独的列表与视频一起使用。

Basically Im trying to bring two seperate lists of customers and another seperate list with videos.

但是当我尝试在customer.cpp选项卡下执行该程序时,我认为它应该运行该程序,但是它运行了video.cpp文件...我在这里缺少什么了吗?

But when I try executing the program under the customer.cpp tab I thought it was supposed to run that but its running the video.cpp file...am I missing something here?

#include <iostream>
using namespace std;

struct video
{
 char title[40],star1[20],star2[20],star3[20],star4[20],prod[20],dir[20],proco[40];
 int copy;
 video *next;
 };
 video *first = NULL, *current = NULL;
  int optn = 0;

^这是我的video.cpp文件列表的节点结构

^this is my nodestructure for the video list the video.cpp file

   #include <iostream>
   using namespace std;

   struct customer
   {
   char f_name[20],l_name[20];
    int acc_num;
    customer *next;
     };
     customer *start = NULL, *pointer = NULL;
     int option = 0;

^这是我的客户链接列表的节点结构。customer.cpp文件。这两个都在

^this is my nodestructure for customer linked list.the customer.cpp file .both of these are in two seperate source files under the same project.

int main(void)
{
 first = NULL;
 current = NULL;
 do
    {
        display();
        cout << endl;
        cout << "Choose an option: " << endl;
        cout << "1. Move the current position forward once." << endl;
        cout << "2. Move the current position backwards once." << endl;
        cout << "3. Add a video at the beginning of the list." << endl;
        cout << "4. Add a video at the current position of the list." << endl;
        cout << "5. Add a video at the ending of the list." << endl;
        cout << "6. Delete the first video from the list." << endl;
        cout << "7. Delete the video at current position from the list." << endl;
        cout << "8. Delete the last video from the list." << endl;
        cout << "9. End program." << endl;
        cout << endl << " >> " ;
        cin >> optn;
         switch (optn)
        {
            case 1 : currentfor();
            break;
            case 2 : currentbac();
            break;
            case 3 : addbeginning();
            break;
            case 4 : addmiddle();
            break;
            case 5 : addending();
            break;
            case 6 : deletebegin();
            break;
            case 7 : deletemiddle();
            break;
            case 8 : deleteend();
            break;
        }
    }
    while (optn != 9);
   }

^这是我调用video.cpp的所有函数的代码

^this is the code where i call all the functions for the video.cpp file.

     int mains(void)
     {
     start = NULL;
     pointer = NULL;
    do
      {
        display_menu();
        cout << endl;
        cout << "Choose an option: " << endl;
        cout << "1. Move the current position forward once." << endl;
        cout << "2. Move the current position backwards once." << endl;
        cout << "3. Add a customer at the beginning of the list." << endl;
        cout << "4. Add a customer at the current position of the list." << endl;
        cout << "5. Add a customer at the ending of the list." << endl;
        cout << "6. Delete the first customer from the list." << endl;
        cout << "7. Delete the customer profile at current position from            the         list." << endl;
        cout << "8. Delete the last video from the list." << endl;
        cout << "9. End program." << endl;
        cout << endl << " >> " ;
        cin >> option;
         switch (option)
        {
            case 1 : current_forward();
            break;
            case 2 : current_backward();
            break;
            case 3 : add_beginning();
            break;
            case 4 : add_middle();
            break;
            case 5 : add_ending();
            break;
            case 6 : delete_beginning();
            break;
            case 7 : delete_middle();
            break;
            case 8 : delete_ending();
            break;
        }
    }
    while (option != 9);

   }

^这是最终的代码,我在其中调用所有函数customer.cpp文件...
当我最初使用int main(void)为customer.cpp尝试时,编译器显示错误,指出在video.cpp和customer.cpp中都声明了 main,所以我尝试将 main更改为 mains,那么它会显示任何错误...我在这里错过了什么?

^this is the final code where i call all functions for customer.cpp file... when I tried initially with int main(void) for the customer.cpp,the compiler showed an error saying that "main" was declared in both video.cpp and customer.cpp so I tried changing "main" to "mains" then it dint show any error...what did I miss here?

推荐答案

如果您只想运行客户实施,则应该具有:

If you wanna run only the customer implementation, you should have:

Customer.h头文件
Customer.cpp-的实施或定义class或其他...
main.cpp-主文件,位于其中:

"Customer.h"-header file "Customer.cpp"- implementation or definitition of the class or whatever... "main.cpp" - the main file, in wich:

#include <iostream>
#include <Customer.h>
int main()
{
  ...
  ...
}

如果您从链接列表类派生了2个不同的类,我认为您应该将客户类和视频类以及每个实现文件分开...

If you have got 2 diferent classes derivated from a linked list class, i think you should split the customer class and the video class, with each implementation files...

如果答案不正确,请添加一些代码以指导您使用类定义:)

If it is not the correct answer, please put some code to guide us with your class definitions :)

这篇关于当我在Code :: Blocks中具有来自同一组源文件的两个.cpp文件时,如何运行其中一个?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆