当我从Code :: Blocks中的同一组源文件中获得两个.cpp文件时,如何运行其中一个?cpp文件?

时间:2011-03-01 03:01:49

标签: c++ codeblocks

我在一个项目的同一组源下有两个不同的.cpp文件(链接列表)。我尝试运行一个名为“customer”的链接列表文件,但它只运行另一个名为“video”的文件。如何运行“客户”链接列表文件?

我的customer.cpp文件处于有效状态,但它仍在运行“视频”链接列表文件的程序。

基本上我试图带两个单独的客户列表和另一个单独的视频列表。

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

#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文件

   #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文件。这些文件在同一个项目下的两个单独的源文件中。

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文件的所有函数的代码。

     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”然后它dint显示任何错误...我在这里错过了什么?

1 个答案:

答案 0 :(得分:1)

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

“Customer.h” - 头文件 “Customer.cpp” - 实施或定义班级或其他...... “main.cpp” - 主文件,位于:

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

如果你有两个不同的类派生自链表类,我认为你应该拆分客户类和视频类,每个实现文件......

如果不是正确的答案,请提供一些代码来指导我们的课程定义:)