Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7836547
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T14:12:12+00:00 2026-06-02T14:12:12+00:00

I have the following program. It is object oriented, having a structure ‘array’ (I

  • 0

I have the following program. It is object oriented, having a structure ‘array’ (I have to use structure defined by me, so vector.h doesn’t count) where I store some objects. The Class functions and the structure work just fine in M.cpp (main) but when I try to call them from controller.cpp I get a reference error.

ListStruct.h:

template <class T>
struct Array{
    int days;
    T * M;

    Array( int size ) : days(size), M(new T[size])
    {
    }
    ~Array()
    {
       delete[] M;
    }
};

void currentDay();

template <class T>
void add(int,int,Array<T> &);

template <class T>
void dummyData(Array<T> &);

ListStruct.cpp

#include <stdlib.h>
#include <iostream>
#include <ctime>

#include "ListStruc.h"
#include "Expe.h"

using namespace std;

int currDay;

void currentDay(){
    time_t t = time(0);   // get time now
    struct tm * now = localtime( & t );
    ::currDay = now->tm_mon + 1;
}

void add(int cant, int type,Array <Expe> &A){
    //Adds to current day the amount to a specific type
    int newVal;
    newVal = A.M[currDay].getObj(type);
    newVal += cant;
    A.M[currDay].editObj(type,newVal);

}

void dummyData(Array <Expe> &A){
    for(int i=0; i<31; i++){
        A.M[i].Expe::setObj((i*3),(i*1),(i*6),(i*2),(i*4),(i*5));
    }
}

M.cpp – main function on the program:

#include <iostream>

#include "Expe.h"
#include "ListStruc.h"
#include "Controller.h"

using namespace std;
int main(){
//Main function of the program. no pre/ post condition.

Array <Expe> A(31);   // Work space
Array <Expe> B(31);   // Backup space

cout<<&A; // testing for allocation
cout<<&B;

Expe a;
a.setObj(5,5,5,5,5,5); // checking class functions
a.printObj();

A.M[1]=a;
A.M[1].printObj();

//check dummy FOR-, WORKS!
for(int i=0; i<31; i++){
    A.M[i].Expe::setObj((i*3),(i*1),(i*6),(i*2),(i*4),(i*5));
}

a.editObj(3,100);
a.printObj();        // check objects calling, WORKS!
cout<<"Obj A.[10]:";
A.M[10].printObj();
cout<<endl<<"Obj A.[29]:";
A.M[29].printObj();

    dummyData(A);  ///////ERROR/////////

ERROR:

D:\c++\Begin\Lab3-5_OOP\Debug/../M.cpp:44: undefined reference to `void dummyData<Expe>(Array<Expe>&)'

I tried everything that I could think of… surfed the internet and still couldn’t find the reason for that reference error.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-02T14:12:17+00:00Added an answer on June 2, 2026 at 2:12 pm

    You are declaring function templates add and dummyData, but defining non-templates.

    If you only need these functions to work on Array<Expe> rather than on generic arrays, then change the declarations to non-templates:

    class Expe;
    void add(int,int,Array<Expe> &);
    void dummyData(Array<Expe> &);
    

    If they need to be generic, then you’ll have to move the definitions into the header file; templates usually need the definition to be available in every source file that uses them. However, your functions appear to be working specifically with Expe, so I don’t think they do want to be templates.

    Also, your Array type is breaking the Rule of Three, making it very dangerous to use. Why don’t you use std::vector to manage the dynamic array safely?

    UPDATE: You say you want to see how to do this while keeping it a template. To do that, you’ll need an explicit specialisation for Expe. That would look something like this:

    template <> void dummyData(Array<Expe> &) {
        // your Expe version goes here
    }
    

    I’m not 100% sure whether or not you’d also need to declare the specialisation in the header file; it’s a long time since I’ve done anything this weird, so I’m not quite sure of the details. Certainly, if you implement the generic version, then you will have to declare this specialisation; otherwise the generic version will be chosen instead. In any event, it’s simpler just to overload the function for Array<Expe>.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have following section of code in my program: object val; val = arr[1].Trim();
I have following commands: // Load the shaders and get a linked program object
I have following structure. #include <iostream> #include <fstream> #include <string> #include <sstream> #include <vector>
I have a question on constant objects. In the following program: class const_check{ int
I have following simple program: import std.stdio; int main(string[] argv) { writeln(Hello, world!); return
I have the following program in which I'm trying to understand the functioning of
I have the following program #include <stdio.h> int main(void) { unsigned short int length
I have the following program where i am calling exit() in the destructor. When
I have the following program: ~/test> cat test.cc int main() { int i =
I have the following program to open lot's of sockets, and hold them open

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.