I have this assignment where I need to program something I guess like a package, so I would be able to include the header file and run the functions from my c++ file in my main c++ file, so what I have is something like this, and it doesn't work :3
__________________________
So the error I keep getting is:
1 IntelliSense: identifier "bubbleSort" is undefined c:\users\padv62090eo\documents\visual studio 2010\projects\sortingalgorithms\sortingalgorithms\sortingalgorithms.cpp 43 2 SortingAlgorithms
I hope you have an idea of what's going on, because I'm pretty lost :/
Refers to a function which is either member of a class or inside a namespace.
You declare int[] bubbleSort(int[] arr); in myHeaderfile.h, which is in the file/global scope, so you do not need the Sort:: in front of the function.
I got it to run in C::B;
Your include hpp int* bubbleSort(int*);
Your function cpp
1 2 3 4 5 6 7 8 9 10 11 12
int* bubbleSort(int* arr)
{
for (int i=1 ; i<10 ; i++)
for (int t=1 ; t<10-i ; t++)
if (arr[t] < arr [t-1])
{
int temp = arr[t];
arr[t] = arr[t-1];
arr[t-1] = temp;
}
return arr;
}
I should say, that it didn't work for me returning an undefined array size (int[]), since you have only 1 array size in your program, why not return a pointer? Note that an array is basically a pointer that has allocated x elements, just not as explicitly as we do with pointers.
Thanks for the reply, I tried to take another approach to it all, and I seem to have it solved somehow :D
I did more or less as you described :3 but now it gives me an error like this:
Unable to start program
missing .dll file
I am not really sure what you mean by that ^_^'
But I don't have an .exe file for the project and since I can't build my program, I can't create one :3
here's the updated code ^^
myLibrary.h
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
#pragma once
usingnamespace System;
namespace myLibrary {
public ref class Class1
{
#ifndef MYSORT
#define MYSORT
void bubbleSort(int arr[]);
void insertionSort(int arr[]);
#endif
};
}
Your include guard is placed wrongly, it should encapsulate the entirety of the header file. "StdAfx.h" in one file and "stdafx.h" in another. Back when I used visual studio, the pre-compiled header was named "stdafx.h", not "StdAfx.h", try renaming that.
what about <math.h>? If you're using an up-2-date IDE I think it should be <cmath>, they did the same for other STL headers like <time.h> being renamed to <ctime>.
Also, I did not include <cmath> when I compiled the project. I think the arithmetics you are using do not utilize anything in <cmath>, so maybe it could be left out.
Apparently it didn't matter having it or not so I guess rand(); is a built in function :3
either that or my program won't give me any errors before I get the dll thingie XD haha
it appears when I try to run the application, it pops up with the window stating that there are errors in the program, then you press continue, and it fails to build because of the missing dll file :3
apparently it should be a myLibrary.dll located in my Debug folder, however it isn't there,
could it be because I made the myLibrary.h a namespace myLibrary?
Well firstly you should put a namespace around both cpp and h content functions. Secondly, you need to call the function in main using the following syntax:
NameSpaceName::FunctionName(Parameters);
Also public ref class Class1
makes no sense to me... I have to go now tho... good luck fixing it !